鍍金池/ 問(wèn)答/HTML5  HTML/ ElementUI中的樹形控件報(bào)錯(cuò)?

ElementUI中的樹形控件報(bào)錯(cuò)?

<el-tree
  :data="data4"
  :props="defaultProps"
  show-checkbox
  node-key="id"
  default-expand-all
  :expand-on-click-node="false"
  :render-content="renderContent">
</el-tree>

<script>
  let id = 1000;

  export default {
    data() {
      return {
        data4: [{
          id: 1,
          label: '一級(jí) 1',
          children: [{
            id: 4,
            label: '二級(jí) 1-1',
            children: [{
              id: 9,
              label: '三級(jí) 1-1-1'
            }, {
              id: 10,
              label: '三級(jí) 1-1-2'
            }]
          }]
        }, {
          id: 2,
          label: '一級(jí) 2',
          children: [{
            id: 5,
            label: '二級(jí) 2-1'
          }, {
            id: 6,
            label: '二級(jí) 2-2'
          }]
        }, {
          id: 3,
          label: '一級(jí) 3',
          children: [{
            id: 7,
            label: '二級(jí) 3-1'
          }, {
            id: 8,
            label: '二級(jí) 3-2'
          }]
        }],
        defaultProps: {
          children: 'children',
          label: 'label'
        }
      }
    },

    methods: {
      append(data) {
        const newChild = { id: id++, label: 'testtest', children: [] };
        if (!data.children) {
          this.$set(data, 'children', []);
        }
        data.children.push(newChild);
      },

      remove(node, data) {
        const parent = node.parent;
        const children = parent.data.children || parent.data;
        const index = children.findIndex(d => d.id === data.id);
        children.splice(index, 1);
      },

      renderContent(h, { node, data, store }) {
        return (
          <span style="flex: 1; display: flex; align-items: center; justify-content: space-between; font-size: 14px; padding-right: 8px;">
            <span>
              <span>{node.label}</span>
            </span>
            <span>
              <el-button style="font-size: 12px;" type="text" on-click={ () => this.append(data) }>Append</el-button>
              <el-button style="font-size: 12px;" type="text" on-click={ () => this.remove(node, data) }>Delete</el-button>
            </span>
          </span>);
      }
    }
  };
</script>

在使用ElementUI中的 tree 樹形控件時(shí)需要?jiǎng)討B(tài)添加DOM元素,但是在使用文檔中給出的案例的時(shí)候會(huì)報(bào)錯(cuò)。
怎么解決?

回答
編輯回答
失魂人

報(bào)什么錯(cuò),沒(méi)錯(cuò)誤定位不了

2018年6月14日 08:31