vue exchange port and cross-domain

匿名 (未验证) 提交于 2019-12-03 00:29:01

1 exchange port : index.js

    // Various Dev Server settings     host: 'localhost', // can be overwritten by process.env.HOST     port: 7777, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined     autoOpenBrowser: false,     errorOverlay: true,     notifyOnErrors: true,     poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- 

2 cross-domain : index.js

    proxyTable: {       '/api': {         target: 'http://localhost:8080',//设置你调用的接口域名和端口号 别忘了加http         changeOrigin: true,         pathRewrite: {           '^/api': ''//这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可         }       }     },

HelloWorld.vue

    <el-row>       <el-button v-on:click="visitMethod()">默认按钮</el-button>     </el-row>    methods: {     visitMethod() {       this.$axios.post('/api/hello')         .then(function (response) {           console.log(response);         })         .catch(function (error) {           console.log(error);         })     }   }



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!