$watch
其实跟watch差不多,但是如果我们想要动态循环绑定watch监听的话,可能使用$watch可能更方便些,如下是el-table进行的循环watch绑定代码片段
registerComplexWatchers() {
// .....
Object.keys(allAliases).forEach(key => {
const columnKey = aliases[key];
this.$watch(key, (newVal) => {
this.columnConfig[columnKey] = newVal;
const updateColumns = columnKey === 'fixed';
this.owner.store.scheduleLayout(updateColumns);
});
});
}
$el
在mounted才会开始有,create的时候都还没有渲染出来呢,代表的是组件自身dom
mounted() {
// .....
const columnIndex = this.getColumnElIndex(children, this.$el);
// ....
},