溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

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

發(fā)布時間:2021-07-20 10:48:04 來源:億速云 閱讀:220 作者:小新 欄目:web開發(fā)

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

首先 下載

npm install vue-class-component vue-property-decorator --save-dev

一梭子直接干;

其次,咱來說說它們的區(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;

開發(fā)時正常引入vue-property-decorator就行

引入后寫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();
 }
}

相當于

export default {
 data () {
 return {
  name: 'Simon Zhang'
 }
 },

 mounted () {
 this.sayHello()
 },

 computed: {
 MyName() {
  return `My name is ${this.name}`
 }
 },

 methods: {
 sayHello() {
  alert(`Hello ${this.name}`)
 },
 }
}

大佬都說爽的一批;

然鵝菜鳥我遇到問題一堆,以下做個積累總結(jié):

1、寫法問題:引入組件和接收父組件傳過來的參數(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)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI