uniapp vue可以通过mixins混入代码,可以通过下面方法混入template

发布时间 2023-11-20 12:04:04作者: 木狼

vue全局混入template方法:在根目录vue.config.js(没有就新增)里添加一下代码

//红色部分是混入的自定义vue组件
module.exports = { chainWebpack: config => { config.module.rule('vue').use('vue-loader').loader('vue-loader').tap(options => { const compile = options.compiler.compile options.compiler.compile = (template, ...args) => { if (args[0].resourcePath.match(/^pages/)) { template = template.replace(/[\s\S]+?<[\d\D]+?>/, _ => `${_} <updagrade ref="updagrade" />`) } return compile(template, ...args) } return options }) } }