【发布时间】:2019-05-26 01:15:37
【问题描述】:
我遇到的问题似乎是 axios 在发布到构建时忽略了我的 GET 路径,但在开发模式下按预期工作。
我正在使用以下内容来检索本地 .html 文件并将它们解析到我的 vue 组件中。
<template>
<div>
<div v-html="message"></div>
</div>
</template>
<script>
import axios from 'axios';
export default {
data () {
return {
message: '',
}
},
async mounted(){
const mypath = 'http://***.com/posts/' + this.$route.params.post + '.html';
const ip = await this.$axios.$get(mypath);
this.message = ip;
}
}
</script>
这个 .vue 位于“pages/blogs/posts/_post.vue”
我的 .html 文件位于“static/posts/examplepost.html”中
在开发模式下运行时,如果我将路径的第一部分更改为“http://localhost:3000/posts/”或只是“/posts/”,一切正常。
但是,当我发布到网络并链接到博客文章 url 时,我在以下路径得到 404:"https://***.com/blogs/posts/examplepost.html"
为什么这在开发模式下工作,但在构建时却不行?
我尝试将帖子移动到“/blogs/posts/”位置,并尝试创建一个新的 axios 实例并直接在我的组件中设置 baseURL 并获得相同的结果。
【问题讨论】:
标签: javascript vue.js axios nuxt.js