html引入vue组件属性,app.vue组件如何按需加载?

fef70804b6966363311ff209820d44c9.png

app.vue组件如何按需加载?

按需加载组件,或者异步组件,主要是应用了component的 is 属性

1、template中的代码:

这里的每一个按钮,都要显示不同的组件,所以我让他们使用了同一个方法名

type="text"

size="mini"

@click="handleSchedule('CustomerInfoSchedule', scope.row.customer_id)"

>详情

type="text"

size="mini"

@click="handleSchedule('VisitRecordSchedule', scope.row.customer_id)"

>回访

type="text"

size="mini"

@click="handleSchedule('AddCustomerSchedule',scope.row.customer_id)"

>编辑

type="text"

size="mini"

@click="handleSchedule('AddPeopleSchedule', scope.row.customer_id)"

>添加联系人

:is="currentComponent"

:customer_id="customer_id"

@componentResult="componentResult"

>

2、script中的代码:

这里的组件使用request按需引入,我使用的点击事件,当事件触发的时候,引入对应的组件

首先在data中声明组件的属性data() {

return {

currentComponent: "",

customer_id:'',

}

}

3、然后注册组件

这里的组件作为一个个方法,组件名是方法名,组件内容是方法体,有几个组件就写几个方法components: {

AddCustomerSchedule(resolve) {

require(["../components/AddCustomer"], resolve);

},

AddPeopleSchedule(resolve) {

require(["../components/AddPeople"], resolve);

},

CustomerInfoSchedule(resolve) {

require(["../components/CustomerInfo"], resolve);

},

VisitRecordSchedule(resolve) {

require(["../components/VisitRecord"], resolve);

},

},

4、定义的方法// 这里直接接收name,然后相对应的引入组件,同时传值

handleSchedule(name, id) {

this.customer_id = id;

this.currentComponent = name;

},

// 这是子组件触发父组件返回回来的方法,因为我的组件都是弹出框

// 所以在子组件关闭弹出框的时候,我让this.currentComponent为空

// 同时可以选择性的刷新数据

componentResult(type) {

if (type == "upData") {

this.getTableData();

} else {

this.currentComponent = "";

}

},

更多Vue.js相关技术文章,请访问Vue.js答疑栏目进行学习!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值