当我尝试运行nuxt应用程序时,我得到了这个错误。
(index):1 EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection.
下面是我的nuxt.config.js代码
require('dotenv').config()
const development = process.env.NODE_ENV !== 'production'
export default {
srcDir: 'resources/nuxt',
mode: 'spa',
head: {
titleTemplate: '%s - ' + process.env.APP_NAME,
title: process.env.APP_NAME || '',
link: [
{ rel: 'icon', type: 'image/png', href: '/ico2.png' },
{
rel: 'stylesheet',
href: 'https://unicons.iconscout.com/release/v2.1.9/css/unicons.css'
}
],
laravel: { publicDir: 'public_html' },
bootstrapVue: { icons: true },
router: { base: '/' },
axios: { baseURL: development ? process.env.DEV_URL : undefined },
build: { extend(config, ctx) {} },
server: {
port: 8000
}
}
我正在尝试从存储中获取一些数据,它正在从API断点获取数据,如下所示:
import axios from 'axios'
export const state = () => ({
apiItems: []
})
export const mutations = {
SET_API(state, apiItems) {
state.apiItems = apiItems
}
}
export const actions = {
async GET_API({ commit }) {
const { data } = await axios.get('api/dummy_api')
commit('SET_API', data)
}
}
在我的页面文件中:
async fetch({ store, params }) {
await store.dispatch('adsl/GET_API')
})
有人能帮上忙吗!
发布于 2020-09-17 16:53:09
您需要在客户端和服务器端设置application/json mime类型。
以下是后端的PHP示例:
header('Content-Type: application/json');
echo json_encode($result);
frotend的axios示例:
axios.get('my/url', {
headers: {
'Content-Type': 'application/json'
}
})
https://stackoverflow.com/questions/63933834
复制相似问题