我尝试在vue-cli中使用环境变量,但是不起作用,每次使用时都说'undefined' console.log(process.env.VUE_APP_BASE_URI).但是process.env.NODE_ENV我在webpack.config.js中定义了'开发'.
我阅读了vue-cli 3的文档,并将我的.env.*文件放在根项目中.像这样:

Webpack.config.js
module.exports = {
mode: 'development',
context: __dirname,
entry: {
main: ['babel-polyfill', './App/index.js']
},
plugins:[
new VueLoaderPlugin()
],
Run Code Online (Sandbox Code Playgroud)
.env.development
VUE_APP_BASE_URI=http://localhost:64208/api/
Run Code Online (Sandbox Code Playgroud)
.env.production
VUE_APP_BASE_URI=http://localhost:64208/api/
Run Code Online (Sandbox Code Playgroud)
我使用带有Vue的.NET Core.如何使用环境?
我想获取vue-router当前路由的名称,我有一个带有导航到其他componentes的组件菜单,因此我想显示当前路由的名称。我有这个:
created(){
this.currentRoute;
//this.nombreRuta = this.$route.name;
},
computed:{
currentRoute:{
get(){
this.nombreRuta = this.$route.name;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是路由名称的标签不会更改,标签仅显示第一个加载的路由的名称。谢谢
编辑:
显示我想要的图像
我有一个4.23.1版的 Webpack,并使用 TerserWebpackPlugin 来缩小我的项目。我想在生产中删除 console.log,但它不起作用。我尝试了 UglifyJsplugin,但都没有。
这是我的webpack.config.js文件:
var path = require('path')
var webpack = require('webpack')
const bundleOutputDir = './wwwroot/dist';
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const configs = require('./wwwroot/js/config')
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
mode: 'production',
optimization:{
minimizer:[
new TerserPlugin({
terserOptions:{
cache: true,
parallel: true,
sourceMap: false,
compress:{
drop_console: true,
}
}
})
]
},
context: __dirname,
entry: {
main: ['babel-polyfill', './App/index.js']
},
plugins:[
new VueLoaderPlugin(),
new webpack.DefinePlugin({
'SERVICE_URL': JSON.stringify(configs.url),
}),
],
module: {
rules: [...] …Run Code Online (Sandbox Code Playgroud) index.js好的,如果状态代码为 ,我有一个拦截器来刷新令牌401,这工作正常,但是在登录页面中,如果我从服务器返回另一个状态代码,则页面中的消息错误不起作用,因为axios不接收A 401。
但如果收到401,拦截器就可以正常工作。
这是有关该内容的屏幕截图。404如果没有找到用户,它会从服务器返回 a 。\n
该错误与 相关Login.vue,但如果我删除axios.interceptors我的index.js“状态”中的Login.vue,它就可以正常工作。
拦截器
\naxios.interceptors.response.use(response => {\n return response;\n}, error => {\n if (error.response.status === undefined) {\n return;\n } else {\n const code = error.response.status;\n if (code === 401) {\n localStorage.removeItem("token");\n axios.get("token/refresh", {\n params: {\n correo: window.localStorage.getItem("email")\n }\n }).then(response => {\n var refresh_token = response.data.token;\n localStorage.setItem("token", refresh_token);\n }).catch(error => {\n const …Run Code Online (Sandbox Code Playgroud) 我需要填充一个 Vuetify select,但它有问题,我的 Get 方法返回数据,但 vuetify select 只显示如下内容:

文本显示有效数据:
[ { "id": 1 }, { "id": 2 } ]
Run Code Online (Sandbox Code Playgroud)
并填充 Select 我按照文档添加 :items="entidades" and :item-text="entidades.id" and :item-value="entidades.id"
<v-select :items="entidades" :item-text="entidades.id" :item-value="entidades.id" single-line auto prepend-icon="group_work" label="Seleccionar Grupo"></v-select>
Run Code Online (Sandbox Code Playgroud)
这是我的代码表单脚本
`data() {
return(){
entidades: [{
id: ''
}],
}
}`
Run Code Online (Sandbox Code Playgroud)
我已经尝试输入 0,但结果相同。
我的 axios.get 方法。
axios.get('http://localhost:58209/api/GetEntidades', {
headers:{
"Authorization": "Bearer "+localStorage.getItem('token')
}
})
.then(response => {
console.log(response)
this.entidades = response.data;
})
.catch(error => {
console.log(error.response)
});
Run Code Online (Sandbox Code Playgroud)
非常感谢
vue.js ×3
axios ×2
html-select ×1
javascript ×1
vue-cli-3 ×1
vue-router ×1
vuetify.js ×1
webpack ×1