vue-cli+typescript 搭建

一、搭建vue-clivue

vue init webpack myVue

二、安裝插件node

cd myVue

npm/cnpm   typescript ts-loader vue-class-component vue-property-decorator --save-dev

npm install

三、配置 webapckwebpack

//修改目錄下bulid/webpack.base.conf.js,在module>rules下添加

{
        test: /\.tsx?$/,
        loader: 'ts-loader',
        exclude: /node_modules/,
        options: {
          appendTsSuffixTo: [/\.vue$/],
        }
}
//修改下的爲
webpack.base.conf.jsentry>app'./src/main.ts'

四、在src下 添加 .d.ts 如(vue.d.ts)後綴文件名程序員

declare module "*.vue" {
  import Vue from 'vue';
  export default Vue;
}

五、在項目根目錄下創建TypeScript配置文件tsconfig.jsonweb

{
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules"
  ],
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "module": "es2015",
    "target": "es5",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "isolatedModules": true,
    "lib": [
      "dom",
      "es5",
      "es2015.promise"
    ],
    "sourceMap": true,
    "pretty": true
  }
}

六、重命名src下的main.js爲  main.tsvue-cli

七、修改src下的App.vue文件下typescript

<script lang="ts">

八、測試npm

<script lang="ts">
import Vue, {ComponentOptions} from 'vue'
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  }
} as ComponentOptions<Vue>
</script>

 程序員兼職json

能夠加我微信進羣,有資料送,也能夠討論問題promise

相關文章
相關標籤/搜索