Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何调用外部API #2819

Open
hanlimo opened this issue Dec 6, 2019 · 4 comments
Open

如何调用外部API #2819

hanlimo opened this issue Dec 6, 2019 · 4 comments

Comments

@hanlimo
Copy link

hanlimo commented Dec 6, 2019

@liyang5945
Copy link

这样试试,我实测这样调用公网接口是OK的
.env.development文件:

VUE_APP_BASE_API = '/dev-api'

vue.config.js:

proxy: {
      // change xxx-api/login => mock/login
      // detail: https://cli.vuejs.org/config/#devserver-proxy
      [process.env.VUE_APP_BASE_API]: {
       target: `http://127.0.0.1:8848/go`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      }

@hanlimo
Copy link
Author

hanlimo commented Dec 9, 2019

感谢回复,我之前也这样配置过,但是proxy没有生效,依然会访问‘http://localhost:9528/dev-api/go’并报404.

@androidvm
Copy link

androidvm commented Dec 9, 2019

[process.env.VUE_APP_BASE_API + '/go']: {

@ghost
Copy link

ghost commented May 18, 2020

直接用axios为什么会报错 我直接这样用吊用第三方接口是可以返回数据的
import axios from "axios"

// 登记退款银行信息
savebank() {
// 调用阿里接口判断银行卡号是否合法
var url = "https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&" + "cardNo=" + this.bank.no + "&cardBinCheck=true"
axios.get(url).then(response => {
if (response.data.validated == false) {
this.$message({
type: 'error',
message: '银行卡号不合法,请确认'
});
this.dialogFormVisible = true
} else {
// 如果合法,把银行提交到后台

      this.dialogFormVisible = false
    }
  })

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants