vue3+iview展现各自树的页面
时间: 2023-08-10 21:39:53 浏览: 64
首先,你需要在你的 Vue3 项目中安装 iview 组件库,可以使用以下命令:
```
npm install iview --save
```
然后你需要在你的 Vue3 项目中引入 iview 组件库。在你的 main.js 文件中添加以下代码:
```javascript
import { createApp } from 'vue'
import App from './App.vue'
import iView from 'iview';
import 'iview/dist/styles/iview.css';
createApp(App).use(iView).mount('#app')
```
接着,你需要创建两个组件来展示各自的树。你可以使用 iview 组件库中的 Tree 组件来展示树。例如,你可以创建以下两个组件:
```vue
<template>
<div>
<i-tree :data="treeData" :options="treeOptions"></i-tree>
</div>
</template>
<script>
export default {
name: 'TreeA',
data() {
return {
treeData: [
{
title: 'Node 1',
expand: true,
children: [
{
title: 'Child 1',
expand: true,
children: [
{
title: 'Grandchild 1'
},
{
title: 'Grandchild 2'
}
]
},
{
title: 'Child 2'
}
]
}
],
treeOptions: {
showCheckbox: true
}
}
}
}
</script>
```
```vue
<template>
<div>
<i-tree :data="treeData" :options="treeOptions"></i-tree>
</div>
</template>
<script>
export default {
name: 'TreeB',
data() {
return {
treeData: [
{
title: 'Node 1',
expand: true,
children: [
{
title: 'Child 1'
},
{
title: 'Child 2'
}
]
}
],
treeOptions: {
showCheckbox: false
}
}
}
}
</script>
```
最后,你需要在你的路由中定义这两个组件的路由。例如:
```javascript
import { createRouter, createWebHistory } from 'vue-router'
import TreeA from './components/TreeA.vue'
import TreeB from './components/TreeB.vue'
const routes = [
{ path: '/treeA', component: TreeA },
{ path: '/treeB', component: TreeB }
]
const router = createRouter({
history: createWebHistory(),
routes
})
export default router
```
这样,你就可以在你的应用程序中访问这两个组件并展示各自的树了。例如,你可以在你的应用程序中使用以下链接来访问这两个组件:
```
http://localhost:8080/#/treeA
http://localhost:8080/#/treeB
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)