zoukankan      html  css  js  c++  java
  • vue 动态组件的传值

    vue项目开发中会用到大量的父子组件传值,也会用到动态组件的传值,常规子组件获取父组件的传值时,第一次是获取不到的,这时候有两种解决方案

    第一种:

    父组件向子组件传的是一个json对象,ES6的方法Object.keys() 转化成数组,再判断数组的长度。如果传的是数组,直接判断长度就行

    <!--父组件动态内容区域-->
    <component :is="currentView" :clientDetails="clientDetails" v-if="Object.keys(clientDetails).length > 0"></component>

    第二种:

    第二种方法是子组件监听处理

    <!--父组件动态内容区域-->
    <component :is="currentView" :clientDetails="clientDetails"></component>
    复制代码
    <!--子组件监听-->
    watch: { clientDetails(newVal){ this.expandDetail = newVal; console.log(this.expandDetail); } },
    复制代码

    注::is="currentView"是用来控制动态组件的,currentView的值改变会使用不同的子组件

    贴一段项目中用到的代码

    // 左侧菜单切换
    handleChangeMenu (code) {
        this.currentView = code
    },
    复制代码
    components:{
        expand: () => import('../groups/expand'),
        certificates: () => import('../groups/certificates'),
        contacts: () => import('../groups/contacts'),
        addressview: () => import('../groups/addressview'),
        credit: () => import('../groups/credit')
    }
    复制代码
  • 相关阅读:
    Random生成随机数
    Jmeter(八)Jmeter监控tomcat
    Jmeter(七)Mongodb的增删改查
    Jmeter(六)文件上传和下载文件
    Jmeter(五)mysql的增删改查
    Jmeter(四)测试webservice脚本
    Jmeter(三)断言和关联
    Jmeter(二)参数化
    Jmeter(一)http接口添加header和cookie
    Python学习笔记(一)数据类型
  • 原文地址:https://www.cnblogs.com/hellofangfang/p/11531464.html
Copyright © 2011-2022 走看看