最初我以為在nuxtjs中是需要重新npm install axios,但是其實nuxtjs自己集成了這個數據渲染方法
你只需在nuxt.config.js中配置一下就可以了
modules: [
// Doc: https://github.com/nuxt-community/axios-module#usage
'@nuxtjs/axios'
],
/*
** Axios module configuration
*/
axios: {
proxy: true,
prefix: '/api/',
credentials: true
// See https://github.com/nuxt-community/axios-module#options
},
proxy: {
'/api/': {
target: 'https://h5api.zhefengle.cn',//這個網站是開源的可以請求到數據的
pathRewrite: {
'^/api/': '/',
changeOrigin: true
}
}
},
然后在你的頁面可以直接請求數據了
mounted() {
this.$axios.get("/index.html").then(res=>{
console.log(res)
})
},
最后進入這個頁面,在控制台看到打印即表示請求成功了