一开始的代码
<el-dialog title="编辑菜单" :visible.sync="editmenu" width="30%" >
<el-tree
:data="menu"
show-checkbox
:default-expand-all = "true"
node-key="id"
ref="tree"
highlight-current
:props="prop"
>
</el-tree>
<div slot="footer" class="dialog-footer" >
<el-button @click="editmenu = false">取 消</el-button>
<el-button type="primary" @click="saveMenu">确 定</el-button>
</div>
</el-dialog>
效果:
只选一个子菜单就选不中父菜单
解决办法:增加属性check-strictly
<el-dialog title="编辑菜单" :visible.sync="editmenu" width="30%" >
<el-tree
:data="menu"
show-checkbox
:default-expand-all = "true"
node-key="id"
ref="tree"
highlight-current
:props="prop"
check-strictly>
</el-tree>
<div slot="footer" class="dialog-footer" >
<el-button @click="editmenu = false">取 消</el-button>
<el-button type="primary" @click="saveMenu">确 定</el-button>
</div>
</el-dialog>
效果:
如果不选择父菜单会导致数据库中没有父菜单,后端返回动态菜单的时候就查询不到子菜单了。