首先 下載
npm install vue-class-component vue-property-decorator --save-dev
一梭子直接干;
其次,咱來(lái)說(shuō)說(shuō)它們的區(qū)別與聯(lián)系:
vue-property-decorator社區(qū)出品;vue-class-component官方出品
vue-class-component提供了Vue、Component等;
vue-property-decorator深度依賴了vue-class-component,拓展出了更多操作符:@Prop、@Emit、@Inject、@Model、@Provide、@Watch;
開(kāi)發(fā)時(shí)正常引入vue-property-decorator就行
引入后寫(xiě)vue代碼就是如此,
import {Component, Prop, Vue} from 'vue-property-decorator' @Component export default class App extends Vue { name:string = 'Simon Zhang' // computed get MyName():string { return `My name is ${this.name}` } // methods sayHello():void { alert(`Hello ${this.name}`) } mounted() { this.sayHello(); } }
相當(dāng)于
export default { data () { return { name: 'Simon Zhang' } }, mounted () { this.sayHello() }, computed: { MyName() { return `My name is ${this.name}` } }, methods: { sayHello() { alert(`Hello ${this.name}`) }, } }
大佬都說(shuō)爽的一批;
然鵝菜鳥(niǎo)我遇到問(wèn)題一堆,以下做個(gè)積累總結(jié):
1、寫(xiě)法問(wèn)題:引入組件和接收父組件傳過(guò)來(lái)的參數(shù)
@Component({ components: { XXXX }, props: { mapFlag: Number } })
2、獲取refs,在其后面加上as HTMLDivElement(不知道是不是這插件引起的,懶得管,直接干就是)
let layoutList:any = this.$refs.layout as HTMLDivElement
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com