新建一个js文件、如图 js文件名字叫ApiServer

let apiUrl='www.huashengshu.top:3000'

export default {
  apiUrl:apiUrl
}

使用方法:

在需要使用的地方引入该js文件

<template>
  <div>
    <button @click="this.test">测试引入</button>
  </div>
</template>

<script>
import Api from './SpiServer'  //import js别名  from  引入的js文件
// 下面的都可以使用,使用方法是通过Api.apiUrl引用

 export default {
    name: 'Music',
    methods: {
      test(){
        console.log(API.apiUrl)
        alert(API.apiUrl)
      },
    }
}
</script>

会在控制台输出以及会弹窗得到  www.huashengshu.top:3000 字符串

Logo

前往低代码交流专区

更多推荐