vscode中vue開發遇到的一些小問題

1.this問題

不要在選項屬性或回調上使用箭頭函數,
比如 
created: () => console.log(this.a) 或
vm.$watch('a', newValue => this.myMethod())。
因爲箭頭函數是和父級上下文綁定在一起的,this 不會是如你所預期的 Vue 實例,
經常導致 Uncaught TypeError: Cannot read property of undefined 或
 Uncaught TypeError: this.myMethod is not a function 之類的錯誤。

2.使用vscode遇到代碼eslint自動將單引號換成雙引號問題,解決辦法:在VScode設置(setting.json)中,配置如下規則,將下面的條件true換成false

// Validate vue-html in <template> using eslint-plugin-vue

"vetur.validation.template": true

不行的話,使用

"prettier.singleQuote": true,
"prettier.semi": false,
"vetur.format.defaultFormatter.html": "js-beautify-html",
"vetur.format.defaultFormatterOptions": {
    "wrap_attributes": "force-aligned"
 },

這是因爲在VSCode1.7.2中替換了內置格式化插件。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章