vue 例項順序
阿新 • • 發佈:2021-10-22
Vue官網文件中也有推薦
-
Vue擴充套件: extends, mixins, components
-
Vue資料: props, model, data, computed, watch
-
Vue資源: filters, directives
-
Vue生命週期: created, mounted, destroy...
-
Vue方法: methods
以下推薦順序,基於團隊小夥伴@akimoto整理的順序:
export default {
name: '',
/*1. Vue擴充套件 */
extends: '', // extends和mixins都擴充套件邏輯,需要重點放前面
mixins: [],
components: {},
/* 2. Vue資料 */
props: {},
model: { prop: '', event: '' }, // model 會使用到 props
data () {
return {}
},
computed: {},
watch:{}, // watch 監控的是 props 和 data,有必要時監控computed
/* 3. Vue資源 */
filters: {},
directives: {},
/* 4. Vue生命週期 */
created () {},
mounted () {},
destroy () {},
/* 5. Vue方法 */
methods: {}, // all the methods should be put here in the last
}