interview-answe icon indicating copy to clipboard operation
interview-answe copied to clipboard

204.[vue]Vue 中相同逻辑如何抽离?

Open webVueBlog opened this issue 4 years ago • 1 comments

[vue]

webVueBlog avatar Apr 21 '20 01:04 webVueBlog

实现:使用 Vue.mixin,给组件每个生命周期,注入一些公共逻辑 核心是 mergeOption 语法:

Vue.mixin(
	data() {
		return {
			//...
		}
	},
	beforeCreate() {
		// ...
	}
)

webVueBlog avatar Apr 21 '20 01:04 webVueBlog