vue按需加载组件,异步组件
说实话,我一开始也不知道什么叫按需加载组件,组件还可以按需加载???后来知道了
学不完啊...没关系,看我的
按需加载组件,或者异步组件,主要是应用了component的 is 属性
template中的代码:
这里的每一个按钮,都要显示不同的组件,所以我让他们使用了同一个方法名
<template slot-scope="scope">
<el-button
type="text"
size="mini"
@click="handleSchedule('CustomerInfoSchedule', scope.row.customer_id)"
>详情</el-button>
<el-button
type="text"
size="mini"
@click="handleSchedule('VisitRecordSchedule', scope.row.customer_id)"
>回访</el-button>
<el-button
type="text"
size="mini"
@click="handleSchedule('AddCustomerSchedule',scope.row.customer_id)"
>编辑</el-button>
<el-button
type="text"
size="mini"
@click="handleSchedule('AddPeopleSchedule', scope.row.customer_id)"
>添加联系人</el-button>
</template>
<component
:is="currentComponent"
:customer_id="customer_id"
@componentResult="componentResult"
>
</component>
script中的代码:
这里的组件使用request按需引入,我使用的点击事件,当事件触发的时候,引入对应的组件
首先在data中声明组件的属性
data() {
return {
currentComponent: "",
customer_id:'',
}
}
然后注册组件
这里的组件作为一个个方法,组件名是方法名,组件内容是方法体,有几个组件就写几个方法
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);
},
},
定义的方法
// 这里直接接收name,然后相对应的引入组件,同时传值
handleSchedule(name, id) {
this.customer_id = id;
this.currentComponent = name;
},
// 这是子组件触发父组件返回回来的方法,因为我的组件都是弹出框
// 所以在子组件关闭弹出框的时候,我让this.currentComponent为空
// 同时可以选择性的刷新数据
componentResult(type) {
if (type == "upData") {
this.getTableData();
} else {
this.currentComponent = "";
}
},
vue按需加载组件,异步组件的更多相关文章
- Vue按需加载提升用户体验
Vue官方文档异步组件: 在大型应用中,我们可能需要将应用拆分为多个小模块,按需从服务器下载.为了让事情更简单, Vue.js 允许将组件定义为一个工厂函数,动态地解析组件的定义.Vue.js 只在组 ...
- vue按需加载组件-webpack require.ensure
使用 vue-cli构建的项目,在 默认情况下 ,执行 npm run build 会将所有的js代码打包为一个整体, 打包位置是 dist/static/js/app.[contenthash].j ...
- vue 按需加载,缓存,导航守卫
开发中的注意事项:代码性能的优化 1. 减少对第三方的依赖,降低耦合度 2. 加强组件的重复利用率 3. 按需加载 4. 缓存 (尽量发送请求后保存数据) 5. 开发过程中,尽量有着面向对象的思想,这 ...
- vue 按需加载
vue 构建单页面应用,但是问题是随着系统的体积变大,js文件也体积太大了,这时候就需要按需要进行加载了 vue-router提供了懒加载的方式 const Foo = resolve => r ...
- router 配置按需加载对应的组件,配置active
const routes = [ { path: '/', component: App, children: [ {path: '/index/:type', name: 'index', comp ...
- 三步解决 vue 按需加载
1 webpack 的 output 配置 chunkFleName 树干名称: " chunks/[name]-[chunkhash:8].js " 这一步是配合第三步, 生 ...
- 仿ElementUI构建自己的Vue组件库用babel-plugin-component按需加载组件及自定义SASS主题
最近使用ElementUI做项目的时候用Babel的插件babel-plugin-component做按需加载,使得组件打包的JS和CSS包体积大大缩小,加载速度也大大提升,所有想模仿做一个组件库也来 ...
- React Router 4.0 + webpack 实现组件按需加载
网上关于React Router 4.0的按需加载文章有很多,大致的思路都一样,但是其实具体实现起来却要根据自己的实际情况来定,这里主要介绍一下我的实现方式. 主要方式是通过Route组件的rende ...
- vue中路由按需加载的几种方式
使用vue-cli构建项目后,我们会在Router文件夹下面的index.js里面引入相关的路由组件,如: import Hello from '@/components/Hello' import ...
随机推荐
- Intersection of Two Linked Lists(链表)
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- httpclient失败重连机制
HttpClient 底层会默认超时自动重发3次,DefaultHttpRequestRetryHandler源码 /** * Create the request retry handler ...
- CentOS 6.x DRBD
CentOS 6.x DRBD 一.drbd概述 Distributed Replicated Block Device(DRBD)是一种基于软件的,无共享,复制的存储解决方案,在服务器之间的 ...
- css中使input输入框与img(图片)在同一行居中对齐
input,img{vertical-align:middle;},同时设置input和img的vertical-align属性,兼容ie7
- Hibernate也须要呵护——Hibernate的泛型DAO
众所周之.面向对象的基础是抽象.也能够说,抽象促使编程在不断发展. 对于数据库的訪问,以前写过HqlHelper.EFHelper.编写Spring+Hibernate框架下的应用.也相同离不了编写一 ...
- 【日常学习】codevs1287 矩阵乘法题解
转载请注明出处 [ametake版权全部]http://blog.csdn.net/ametake欢迎来看. 先上题目 题目描写叙述 Description 小明近期在为线性代数而头疼,线性代数确实非 ...
- oracle 导出导入不含数据的空库
10g或之前,用exp导出,imp导入,带上rows=n参数 11g或以上,用expdp导出,impdp导入,带上CONTENT = METADATA_ONLY 参数 expdp带上此参数,不导出数据 ...
- Vue框架之组件系统
1,Vue组件系统之全局组件 1.1Vue全局组件的在实例化调用Vue的模板中导入组件的名称 <!DOCTYPE html> <html lang="zh-cn" ...
- 在myeclipse下面创建多层包
比如animal.cat.dog包 先创建animal包 然后创建animal.cat包 最后创建animal.cat.dog包 最后你发现这三个文件夹是分层的,层层嵌套的三个文件夹,而不是一个文件夹 ...
- What are some advantages of using Node.js over a Flask API?
https://www.quora.com/What-are-some-advantages-of-using-Node-js-over-a-Flask-API Flask is a Python w ...