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
中替換了內置格式化插件。