TypeScript+Vue插件vue-class-component的使用示例

這篇文章給大家分享的是有關(guān)TypeScript+Vue插件vue-class-component的使用示例的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。

成都創(chuàng)新互聯(lián)專(zhuān)注于寬甸企業(yè)網(wǎng)站建設(shè),自適應(yīng)網(wǎng)站建設(shè),購(gòu)物商城網(wǎng)站建設(shè)。寬甸網(wǎng)站建設(shè)公司,為寬甸等地區(qū)提供建站服務(wù)。全流程按需求定制開(kāi)發(fā),專(zhuān)業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)專(zhuān)業(yè)和態(tài)度為您提供的服務(wù)

首先 下載

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

感謝各位的閱讀!關(guān)于“TypeScript+Vue插件vue-class-component的使用示例”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

網(wǎng)頁(yè)名稱(chēng):TypeScript+Vue插件vue-class-component的使用示例
分享網(wǎng)址:http://muchs.cn/article38/jepesp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、品牌網(wǎng)站設(shè)計(jì)響應(yīng)式網(wǎng)站、面包屑導(dǎo)航、企業(yè)網(wǎng)站制作網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)