/**
* directory {String} -说明需要检索的目录
* useSubdirectories {Boolean} -是否遍历文件的子目录
* regExp {RegExp} - 匹配文件的正则
**/
require.context(directory, useSubdirectories = false, regExp = /^.//);
const files = require.context('@/components', true, /^\.\/(\w*\/)+index\.(vue|js)$/)
export default {
install (Vue) {
files.keys().forEach((path) => {
const type = this.typeof(path, files(path))
// 针对3中不同的组件设计模式提供不同的组件注册策略
switch (type) {
case 'component':
this.installComonent(Vue, files(path));
break;
case 'componentGroup':
this.instalGroupComponent(Vue, files(path));
break;
case 'serveApi':
this.installServeApi(Vue, files(path));
break;
}
})
},
typeof (path, file) {
if (path.lastIndexOf('.js') === -1) {
return 'component'
} else {
if (file.default.install) {
return 'serveApi'
} else {
return 'componentGroup'
}
}
},
instalGroupComponent (Vue, file) {
const components = file.default
Object.keys(components).forEach((name) => {
Vue.component('Nb'+name, components[name])
})
},
installComonent (Vue, file) {
const options = file.default
const name = options.name
Vue.component('Nb'+name, options)
},
installServeApi (Vue, file) {
Vue.use(file.default)
}
}
created(){
this.fetchList()
},
watch: {
'filters.type' () {
this.fetchList()
}
}
watch: {
'filters.type': {
handler: 'getList',
immediate: true
}
}
watch:{
filters: {
handler(newVal,oldVal){
this.getList()
},
deep:true,
immediate: true
}
}
// 使用
// 在双花括号中
{{ message | capitalize }}
// 在 `v-bind` 中
<div v-bind:id='rawId | formatId'></div>
// 全局注册
Vue.filter('stampToYYMMDD', (value) =>{
// 处理逻辑
})
// 局部注册
filters: {
stampToYYMMDD: (value)=> {
// 处理逻辑
}
}
// 多个过滤器全局注册
// /src/common/filters.js
let dateServer = value => value.replace(/(\d{4})(\d{2})(\d{2})/g, '$1-$2-$3')
export { dateServer }
// /src/main.js
import * as custom from './common/filters/custom'
Object.keys(custom).forEach(key => Vue.filter(key, custom[key]))
.result-tab /deep/ {
.nav-bar {
a {
flex: initial;
height: 50px;
font-size: 36px;
margin-left: 40px;
line-height: 100px;
height: auto;
}
}
.result-content {
padding: 0 40px;
}
}
联系客服