Vue.use(Router) let context=require.context('../../static/',true,/\.html$/i) let pages=[] context.keys().forEach(item=>{ let path='../../static/html'+item.slice(1) let split=item.split('/') let name=split[split.length-1].slice(0,-5) let page={ path, name } pages.push(page) })
如果html文件在static文件夹中,则在webpack.base.conf.js中添加以下配置 module: { rules: [ { test:/\.html$/, include:function(content){ return /static/.test(content); }, use:{ loader:'url-loader', options:{ cacheDirectory:true } } }] },