vue设置全局变量

前端调用后端接口的时候,我们固定的前端地址

建立全局变量文件global.vue:

<script>
// 固定的地址
const fortUrl = "http://xxx.xxx.xx.x:8090/intelligentWeavingItems-web/";
export default {
  fortUrl
};
</script>

 在main.js文件中进行挂载:


import global_ from './views/addRessList/global.vue'
Vue.prototype.GLOBAL = global_

最后在需要调用后端接口的界面上:

export default {
  name: 'ScanQRCode',
  data () {
    return {      
      getUrl: this.GLOBAL.getUrl,
methods: {
    onSubmit (values) {
      var vm = this
      const url = this.GLOBAL.fortUrl+'approval/commitapproval'
      console.log(url)// 检测一下

猜你喜欢

转载自blog.csdn.net/Ciel_Y/article/details/106339797