在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 在vue中如何配置typescript文件?

在vue中如何配置typescript文件?

1、我想用vue+typescript,但是不知道怎么配置?

clipboard.png

clipboard.png

clipboard.png

clipboard.png

clipboard.png

clipboard.png

系統(tǒng)給我報的錯誤是-------------

clipboard.png

求指教!~謝謝

回答
編輯回答
愚念

webpack.base.conf.js


entry: {
    app: './src/main.js'
  }

.babelrc

     {
          "presets": [
            ["env", {
              "modules": false,
              "targets": {
                "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
              }
            }],
            "stage-2"
          ],
          "plugins": ["transform-vue-jsx", "transform-runtime","transform-decorators-legacy"]
        }
 

vue-shims.d.ts

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

main.js文件不變

tsconfig.json

    
 {
  "compilerOptions": {
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "module": "es2015",
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true,
    "strict": true,
    "target": "es5",
    "moduleResolution": "node",
    "lib": [
      "dom",
      "es5",
      "es2017",
      "es2015"
    ]
  }
}

App.vue

<template>
  <div>
    <input v-model="msg">
    <p>prop: {{propMessage}}</p>
    <p>msg: {{msg}}</p>
    <p>helloMsg: {{helloMsg}}</p>
    <p>computed msg: {{computedMsg}}</p>
    <button @click="greet">Greet</button>
  </div>
</template>

<script>
import Vue from 'vue'
import Component from 'vue-class-component'

@Component({
  props: {
    propMessage: String
  }
})
export default class App extends Vue {
  // initial data
  msg = 123

  // use prop values for initial data
  helloMsg = 'Hello, ' + this.propMessage

  // lifecycle hook
  mounted () {
    this.greet()
  }

  // computed
  get computedMsg () {
    return 'computed ' + this.msg
  }

  // method
  greet () {
    alert('greeting: ' + this.msg)
  }
}
</script>

<style>

#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

</style>

package.json

"dependencies": {
    "awesome-typescript-loader": "^3.4.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "node-sass": "^4.7.2",
    "sass": "^1.0.0-beta.4",
    "sass-loader": "^6.0.6",
    "sass-resources-loader": "^1.3.1",
    "source-map-loader": "^0.2.3",
    "ts-loader": "^3.3.1",
    "typescript": "^2.6.2",
    "vue": "^2.5.2",
    "vue-class-component": "^6.1.2",
    "vue-router": "^3.0.1"
  },



https://github.com/yyccQQu/vu...

2018年1月9日 01:52
編輯回答
墨小白

官網(wǎng)有介紹啊
https://cn.vuejs.org/v2/guide...

2017年6月30日 22:47
編輯回答
囍槑

應(yīng)該是配置loader就可以了

2018年9月21日 10:00
編輯回答
毀與悔

我記得ts寫導(dǎo)入組件要加.vue后綴
第二個router那個我就不知道了。

2017年6月20日 00:57
編輯回答
扯機薄

雖然我也沒有在Vue中具體使用TypeScript,但是官方文檔上有對其的介紹和推薦配置,可以參考一下:https://cn.vuejs.org/v2/guide...

2018年6月19日 23:12