【发布时间】:2018-12-26 14:36:27
【问题描述】:
我使用 nuxt-i18n nuxt-i18n documentation link 在我的网站上获取不同的语言环境:
<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>
它工作得非常好,但我想将此代码转换为在选择元素中呈现:
<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>
语言环境字符串看起来不错,但我没有找到在更改时启动 switchLocalePath 函数的解决方案。有没有合适的方法用 nuxt (vue.js) 做到这一点?
【问题讨论】:
-
this.$router.push(this.switchLocalePath(locale.code)); -
但这必须在每个选项元素中?
-
我的错,你应该改用
selected值(在@change 处理程序中)。 -
我说你需要在
@change函数中使用selected(模型)的值,因为它是select级别上唯一可用的东西;locale.code是对应option元素的属性。 -
在我的脚本中我有这个方法:changeLocale() { this.$router.push(this.switchLocalePath(this.selected)); }
标签: vue.js html-select nuxt.js