vue系列之vue cli 3引入ts

<h1>插件</h1> <a href="http://www.jqhtml.com/26285.html" target="_blank">Vue2.5+ Typescript 引入全面指南</a> <ol> <li> <a href="https://github.com/vuejs/vue-class-component" rel="nofollow noreferrer">vue-class-component</a><br>強化 Vue 組件,使用 TypeScript/裝飾器 加強 Vue 組件</li> <li> <a href="https://github.com/kaorun343/vue-property-decorator" rel="nofollow noreferrer">vue-property-decorator</a><br>在 vue-class-component 上加強更多的結合 Vue 特性的裝飾器</li> <li> <a href="https://github.com/ktsn/vuex-class" rel="nofollow noreferrer">vuex-class</a><br>基於vue-class-component對Vuex提供的裝飾器</li> </ol> <h2>vue-class-component</h2>html

&lt;script lang="ts"&gt;
  import Vue from 'vue'
  import Component from 'vue-class-component'

  @Component
  export default class App extends Vue {
    // 初始化數據
    msg = 123

    // 聲明週期鉤子
    mounted () {
      this.greet()
    }

    // 計算屬性
    get computedMsg () {
      return 'computed ' + this.msg
    }

    // 方法
    greet () {
      alert('greeting: ' + this.msg)
    }
  }
&lt;/script&gt;

<h1>改造.vue</h1> <ol> <li>&lt;script&gt;標籤添加lang="ts"聲明</li> <li>代碼中導入 *.vue 文件的時候,須要寫上 .vue 後綴</li> </ol> <blockquote>緣由仍是由於 TypeScript 默認只識別 <em>.ts 文件,不識別 </em>.vue 文件<br>import Component from 'components/component.vue'</blockquote> <hr> <p>參考連接:<br><a href="https://segmentfault.com/a/1190000011520912">從 JavaScript 到 TypeScript 6 - Vue 引入 TypeScript</a><br><a href="https://segmentfault.com/a/1190000011853167">Vue2.5+ Typescript 引入全面指南</a><br><a href="https://segmentfault.com/a/1190000012486378">多是最全的Vue-TypeScript教程(附實例代碼和一鍵構建工具)</a></p>vue

原文地址:http://www.javashuo.com/article/p-yarxznle-b.htmlgit

相關文章
相關標籤/搜索