1,下载下来公众号官网的txt文件
2,放在vue项目的public文件下
3,新增一个js文件,我放在了util目录下。内容如下:
export function loadFile(url) {
const xhr = new XMLHttpRequest()
const okStatus = document.location.protocol === 'file:' ? 0 : 200
xhr.open('GET', "/MP_verify_J0cjspy3HjQCli8K.txt", false)
xhr.overrideMimeType('text/html;charset=utf-8')// 默认为utf-8
xhr.send(null)
return xhr.status === okStatus ? xhr.responseText : null
}
4,在router下的index.js里添加
router.beforeEach((to, from, next) => {
if(to.path.indexOf('文件名称')>-1){
let url= loadFile('/文件名称.txt')
}
else{
next()
}
})
然后就可以了