将axios url请求写成配置文件

在public目录中新建js

 

baseurl.js

const getUrl='http://localhost:9999/test/test'
console.log(getUrl)

index引用

<script src="./baseurl.js"></script>

在vue页面中可直接引用getUrl

methods:{
  get(){
        let baseurl = getUrl
        this.$http({ method: 'get', url:baseurl , params: data}).then(
          (resp) => {
            console.log(resp.data)
            this.$refs.trc.get(resp.data)
            this.$refs.title.getTitle(acode1,resp.data.newtime)
          }, (error) => {
            console.log('error=' + JSON.stringify(error))
        }).catch((exception) => {
      })
   }  
}    

 

posted @ 2021-01-25 15:58  想学前端的小李  阅读(144)  评论(0)    收藏  举报