• Vue 组件的使用


    1、引入组件

    import Week from '../week/main.vue'
    
    export default {
        name: "classMain",
        components: {
            Week: Week
        },
        data(){
            return {
                schoolID: this.$route.params.id,//学校 id
                portType: "incalss",//incalss,beike,iphone
                isShowChildPages: false
            }
        },
        methods: {
            showChildPage: function () {
                this.isShowChildPages = true;
            },
            closeChildPage: function (data) {
                console.log(data);
                this.isShowChildPages = false;
            },
        }
    } 

    2、显示组件

    <transition name="fade1">
      <Week v-if="isShowChildPages" :portType="portType" @closeChildPage="closeChildPage"></Week>
    </transition>

    3、组件接受参数,并调用父级方法

    export default {
        name: 'weekMain',
        watch: {
            //如果路由发生了变化,更新页面数据
            $route(to, from) {
                if (to.path !== from.path) {
                    this.schoolID = this.$route.params.id;
                }
            }
        },
        props: {
            portType: {
                type: String,
                default: () => {
                    return ''
                }
            }
        },
        data () {
            return {
                schoolID: this.$route.params.id,//学校 id
            }
        },
        methods: {
         //重点 closeChildPage:
    function () { this.$emit('closeChildPage', false); } } }
  • 相关阅读:
    软件测试课堂练习1
    安卓增删改查
    安卓数据库表
    安卓注册登录
    安卓购物清单
    安卓计算器
    第四周安卓作业
    第七周作业
    jsp第六周
    第四次jsp作业
  • 原文地址:https://www.cnblogs.com/sanqianjin/p/10767192.html
Copyright © 2020-2023  润新知