$watch

其实跟watch差不多,但是如果我们想要动态循环绑定watch监听的话,可能使用$watch可能更方便些,如下是el-table进行的循环watch绑定代码片段

  1. registerComplexWatchers() {
  2. // .....
  3. Object.keys(allAliases).forEach(key => {
  4. const columnKey = aliases[key];
  5. this.$watch(key, (newVal) => {
  6. this.columnConfig[columnKey] = newVal;
  7. const updateColumns = columnKey === 'fixed';
  8. this.owner.store.scheduleLayout(updateColumns);
  9. });
  10. });
  11. }

$el

在mounted才会开始有,create的时候都还没有渲染出来呢,代表的是组件自身dom

  1. mounted() {
  2. // .....
  3. const columnIndex = this.getColumnElIndex(children, this.$el);
  4. // ....
  5. },