在一个组件中,我想使用asyncData函数访问商店,如下所示:
asyncData({ app, params }) {
var url = `https://myapi/news/${app.$store.state.market}/detail/${params.id}`;
return app.$axios.get(url).then(response => {
return { actu: response.data };
});
Run Code Online (Sandbox Code Playgroud)
}
但我收到“无法读取未定义的属性'状态'”
这里还有另一个接收商店状态的信息吗?
这是运行良好的实际代码,但我想检查我的标头是否很好地传输到我的 api:
var request = require('request');
var express = require('express');
var router = express.Router();
/* GET data by sportId */
router.get('/:locale/:sportId/:federationId/:date', function(req, res) {
var date = req.params.date;
var locale = req.params.locale;
var sportId = req.params.sportId;
var federationId = req.params.federationId;
request(getEventsOptions(sportId, federationId, date, locale), function(error, response, body) {
res.send(body);
});
});
// get options for request
function getEventsOptions(sportId, federationId, date, locale)
{
return {
url: `http://myapi.com/event/sport/${sportId}/date-from/${date}`,
headers: {
'accept': 'application/json',
'dateTo': date,
'federationIds': federationId,
'X-Application-ID': 'sporter',
'Accept-Language': locale,
}
}; …Run Code Online (Sandbox Code Playgroud) 我使用 nuxt-i18n nuxt-i18n 文档链接在我的网站上获取不同的语言环境,如下所示:
<nuxt-link v-for="locale in $i18n.locales"
v-if="locale.code !== $i18n.locale"
:key="locale.code"
:to="switchLocalePath(locale.code)"
class="locales white--text"
>{{ locale.code }}
</nuxt-link>
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但我想将此代码转换为在选择元素中呈现:
<select v-model="selected" class="locales white--text" @change=" ??? ">
<option disabled value="">{{ $i18n.locale }}</option>
<option v-for="locale in $i18n.locales" :key="locale.code">{{ locale.code }}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
Locales 字符串看起来不错,但我没有找到在更改时启动 switchLocalePath 函数的解决方案。使用 nuxt (vue.js) 有没有合适的方法来做到这一点?
我正在尝试创建一个中间件来将我的所有路由重定向到 https,我想我需要一个中间件,所以我redirect.js在 Nuxt 的中间件文件夹中创建了一个文件,然后将其添加到nuxt.config.js:
router: {
middleware: ["redirect"]
},
Run Code Online (Sandbox Code Playgroud)
这是我的redirect.js文件,它给了我一个服务器错误:
export default function({ app }) {
if (process.env.NODE_ENV === "production") {
if (app.context.req.header("x-forwarded-proto") !== "https") {
app.context.res.redirect(`https://${app.context.req.header("host")}${app.context.req.url}`);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我使用nuxt-i18n在我的应用程序中获得国际化。我有一条新闻清单,列出了这样的路线:
myapp.com/news (default language english)
myapp.com/fr/news
myapp.com/it/news
Run Code Online (Sandbox Code Playgroud)
当我单击新闻时,我想访问_id页,以便仅获取我单击的新闻。所以我这样做的方法(onclick):
onLoadNews(id) {this.$router.push("/news/" + id);}
Run Code Online (Sandbox Code Playgroud)
但是这样一来,我总是回到英语默认语言。如何以这种方式推送语言环境路由(在方法函数中)?
我在我的组件中传递的对象内部收到一个正文(actu.body),里面有 html 标签(主要是 p 标签),我想知道如何为客户端解释它们,我的代码现在是这样的:
<template>
<div>
<!-- {{ actu }} -->
<v-parallax
:src="actu.images[0].url"
dark
>
<v-layout
align-center
column
justify-center
>
<h1 class="display-2 font-weight-thin mb-3">{{ actu.headline }}</h1>
<h4 class="subheading">{{ actu.summarry }}</h4>
</v-layout>
</v-parallax>
<v-card>
<v-card-text>
{{ actu.body }}
</v-card-text>
</v-card>
</div>
</template>
<script>
export default {
props: {
actu: {
type: Object,
required: true
}
Run Code Online (Sandbox Code Playgroud)
} };
有没有正确的方法可以用 vue js 做到这一点?
nuxt.js ×5
vue.js ×3
express ×1
heroku ×1
html ×1
html-select ×1
http ×1
http-headers ×1
javascript ×1
node.js ×1
redirect ×1
vue-router ×1
vuejs2 ×1