vue-jstree安装使用备忘

714 阅读1分钟
原文链接: click.aliyun.com
vue-jstree在这里https://github.com/zdy1988/vue-jstree
我是vue-cli建的项目
npm install vue-jstree --save
组件里这样写
import VJstree from 'vue-jstree'; import axios from "axios"; export default {   name: 'Mytree',   components: {     VJstree   },   data() {     return {       data: []                  }   },   created() {     axios.get('http://192.168.x.x/a2hs/treedata.php')     .then(response => {       this.data=response.data;           })     .catch(e => {       console.log(e)     });   },
动态返回的JSON数据格式如下
[{"id":1,"pid":0,"text":"node1","opened":0,"children":[{"id":43,"pid":1,"text":"node2","opened":0}...]}...]
如果有跨域问题,treedata.php输出前加
header('Access-Control-Allow-Origin: *');