1、与pages同目录新建一个文件夹config,然后在config新建index.js
export default {
path: {
home: '/pages/index/index', //首页
takeOver: '/subpkg/takeOver/index' //收货
}
}
2、在main.js中全局引用并使用
import config from './config/index.js'
Vue.prototype.$config = config;
3、页面中使用
<view class="icon">
<view class="icon_item" v-for="(item,index) in iconListEntry" :key="index" @click="gotoScan(item.pathName)">
<view class="icon_img" :style="{backgroundColor:item.backgroundColor}">
<img class="iconImng" :src="item.iconImg">
</view>
<view class="icon_name">
{{item.name}}
</view>
</view>
</view>
export default {
data() {
return {
iconListEntry: [{
iconImg: require('../../static/images/ReceivingGoods.png'),
name: "收货",
backgroundColor: "#67c2c3",
pathName: 'takeOver'
},
{
iconImg: require('../../static/images/grounding.png'),
name: "上架",
backgroundColor: "#7cb1fd",
}]
}
},
methods: {
gotoScan(path){
if (path) {
uni.navigateTo({
url: this.$config.path[path]
});
} else {
uni.showToast({
icon:'error',
title: '开发中...'
})
}
},
}
}