首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用vue.js从element-ui导入树需要做什么才能使用sloped-slot?

使用vue.js从element-ui导入树需要做什么才能使用sloped-slot?
EN

Stack Overflow用户
提问于 2019-01-29 15:58:20
回答 1查看 601关注 0票数 1

我想创建一个vue组件,它显示一个带有sloped-slot的元素-ui树。

我通过npm install element-ui -S导入了element-ui,它列在我的node_modules文件夹中。

我尝试通过以下代码显示树,但它不起作用。

代码语言:javascript
复制
<template>
  <div>
    <h1>Testing Sloped Slot of element-ui tree with vue.js</h1>

    <el-tree
      :data="data"
      show-checkbox
      node-key="id"
      default-expand-all
      :expand-on-click-node="false">
      <span class="custom-tree-node" slot-scope="{ node, data }">
        <span><b>{{ node.label }}</b></span>

      </span>
    </el-tree>
  </div>
</template>

<script>
  import tree from 'element-ui'

  export default {
    name: 'chart',
    data() {
      return data = [{
        id: 1,
        label: 'Level one 1',
        children: [{
          id: 4,
          label: 'Level two 1-1',
          children: [{
            id: 9,
            label: 'Level three 1-1-1'
          }, {
            id: 10,
            label: 'Level three 1-1-2'
          }]
        }]
      }, {
        id: 2,
        label: 'Level one 2',
        children: [{
          id: 5,
          label: 'Level two 2-1'
        }, {
          id: 6,
          label: 'Level two 2-2'
        }]
      }];
    },
  }

  Vue.use(tree);
</script>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-29 16:25:42

您在data()方法中有一个输入错误。

Vue将从data()对象返回的内容合并到"this“中。因此,如果您有data() { return {a: '1'}; } - a,则可以在this.a中的组件中使用,或者仅在模板中的a中使用。

您的数据()应如下所示:

代码语言:javascript
复制
data() {
  return {
    data: [{
      id: 1,
      label: 'Level one 1',
      children: [{
        id: 4,
        label: 'Level two 1-1',
        children: [{
          id: 9,
          label: 'Level three 1-1-1'
        }, {
          id: 10,
          label: 'Level three 1-1-2'
        }]
      }]
    }, {
      id: 2,
      label: 'Level one 2',
      children: [{
        id: 5,
        label: 'Level two 2-1'
      }, {
        id: 6,
        label: 'Level two 2-2'
      }]
    }]
  };
},
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54416286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档