1. 导入路径
const M = {}function importAll(r) {r.keys().forEach(key => M[key] = r(key))}importAll(require.context('@/api/', true, /\.js$/))console.log('M', M)
2. js代码
constfetchList = M[./${this.key}.js].fetchList
先获取动态的js文件名,通过文件名获取里面的方法函数
getData() {console.log(M)console.log('Key', this.key)this.listLoading = trueconst fetchList = M[`./${this.key}.js`].fetchListfetchList(this.form).then(response => {this.list = response.data.itemsthis.total = response.data.totalthis.listLoading = false})},
