vue跨域解決方式
進行跨頁面訪問數據,出現如下問題
由於跨域的問題
解決方案1:
controller層加上@CrossOrigin註解
或者要訪問那個方法,在方法上寫也可以,就可以訪問了
解決方案二:
配置跨域的相關信息:
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/animalApi': {
target: 'http://localhost:8080/',//設置你調用的接口域名和端口號 別忘了加http
changeOrigin: true, //這裡true表示實現跨域
pathRewrite: {
'^/animalApi': '/' //這裏理解成用‘/api’代替target裏面的地址,後面組件中我們掉接口時直接用api代替 比如我要調用'http://40.00.100.100:3002/user/add',直接寫‘/api/user/add’即可
}
},
},
訪問路徑:
queryAnimalList () {
var self = this
this.$axios.get('/animalApi/animal/queryAnimalList.do').then(function (response) {
self.tableData = response.data
})
},