一、Vue中引用公共方法
1.在src新建common文件夹,再新建common.js
export default({
formatInt:function(num, length) {
return (Array(length).join('0') + num).slice(-length);
}
});
2.main.js引入:
//引入公共方法
import common from './common/common';
Vue.prototype.common =common;
3.使用:
this.common.formatInt(tempOrg,3);//格式化数字,例如8-->:008
@click=“common.方法名”
二、公共组件(例如:多个页面都要用到同一下拉框)
1.在src目录下的components文件夹下新建公共组件
Area.vue:
<template>
<div class="hello">
<div class="block" style="margin-top: 20px;text-align: left">
<label class="demonstration" style="font-weight:bold ">地区:</label>
<el-cascader
:options="orgTree"
:props="{ checkStrictly: true }"
@change="handleChange"
:value="t_org"
clearable></el-cascader