页面代码
<el-tag v-if="downloadfile.downurl && downloadfile.downurl.length > 0">
<a :href="downloadfile.downurl" :download="downloadfile.downname">
资源包下载
</a>
</el-tag>
computed: {
downloadfile: function() {
let path = this.$route.path; // 当前的路径
let index = global.Download_Arr.findIndex(item => item.path === path); // 查找当前路由下的下标
if (index > -1) {
return global.Download_Arr[index];
} else {
return {
downurl: "",
downname: ""
};
}
}
},
定义全局变量globa
//main.js导入
//引入全局的静态变量
import '@/global/global.js'
//global.js页面
// 根据路由配置下载资源包
global.Download_Arr = [
{ name: '普通POI_摄像头', path: '/poi/camera', downurl: '/static/download/richPOI_Electric.zip', downname: 'richPOI_Electric' },
{ name: 'RichPOI_电区', path: '/poi/electric', downurl: '/static/download/richPOI_Electric.zip', downname: 'richPOI_Electric' },
{ name: 'RichPOI_地铁', path: '/poi/metro', downurl: '/static/download/richPOI_Metro.zip', downname: 'richPOI_Metro' },
{ name: 'RichPOI_垃圾车', path: '/poi/garbage', downurl: '/static/download/richPOI_Garbage.zip', downname: 'richPOI_Garbage' }
]
//.vue 页面直接使用
console.log(global.Download_Arr)