请建议从Nuxtjs项目中更改laravel语言环境
我的Laravel后端路线:
Route::get('lang/{locale}', 'LocaleController@index');
语言环境中间件:
if ($request->header('Accept-Language')) {
\App::setLocale($request->header('Accept-Language'));
}
return $next($request);
LocaleController:
App::setLocale($locale);
return response()->json($locale, 200);
Nuxtjs i18n插件:
app.i18n.onLanguageSwitched = (oldLocale, newLocale) => {
console.log(oldLocale, newLocale)
}
在邮递员中测试并工作
我用一行Nuxtjs插件解决了:
app.$axios.defaults.headers.common['Accept-Language'] = newLocale;