JSFiddle - React, Tailwind, and code Playground

by In Roam

HTML

<link rel="stylesheet" href="https://cdn.bootcss.com/iview/2.13.1/styles/iview.css">
<script src="https://cdn.bootcss.com/vue/2.5.16/vue.min.js"></script>
<script src="https://cdn.bootcss.com/iview/2.13.1/iview.min.js"></script>
<div id="app">
		 <row>
			<i-col span="12" offset="6">
		 		<Tree show-checkbox multiple :data="tree"
		 			  @on-check-change="setCheckedList"></Tree>
	        </i-col>

			<!-- 选中的数据 -->
	     <!--    <i-col span="12" offset="6">
	                 <pre>{{ JSON.stringify(checkedList, null, 4) }}</pre>
	        </i-col> -->

	        <i-col span="12" offset="6">
		 		<cascader :data="availableCascaderTree"></cascader>
	        </i-col>
	    </row>
	</div>

JavaScript

const vm = new Vue({
		el: '#app',
		data () {
			return {
				tree: [
					{
						"title": "A",
						"expand": true,
						"children": [
							 {
								"title": "B",
								"expand": true,
								"children": [
									{
										"title": "D",
										"expand": true,
										"children": [
											{
												"title": "H",
												"expand": true,
												"children": []
											}, {
												"title": "I",
												"expand": true,
												"children": [
													{
														"title": "K",
														"expand": true,
														"children": []
													}, {
														"title": "L",
														"expand": true,
														"children": []
													}
												]
											}, {
												"title": "J",
												"expand": true,
												"children": []
											}
										]
									}, {
										"title": "E",
										"expand": true,
										"children": []
									}
								]
							}, {
								"title": "C",
								"expand": true,
								"children": [
									{
										"title": "F",
										"expand": true,
										"children": []
									}, {
										"title": "G",
										"expand": true,
										"children": []
									}
								]
							}
						]
					}
				],
				// 已选中的节点列表
				checkedList: []
			}
		},
		computed: {
			// 原生 tree 转 cascader 组件所需的格式
			cascaderTree () {
				return this.recursion(JSON.parse(JSON.stringify(this.tree)))
			},
			// 已选中节点 map 映射
			checkedMap () {
				const map = {}

				this.checkedList.forEach((item) => {
					map[item.title] = item
				})

				return map
			},
			// 计算出可选择的 tree,用于 cascader 组件
			availableCascaderTree () {
                let tree = JSON.parse(JSON.stringify(this.cascaderTree))

                tree = this.setAvailable(tree)

                return tree
            }
		},
		methods: {
			/**
			 * 递归,用于 tree 转 cascaderTree
			 * @param  {[type]} tree [description]
			 * @return {[type]}      [description]
			 */
			recursion...