小编Isa*_*edo的帖子

如何使用vue-cli 3配置环境变量?

我尝试在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.如何使用环境?

environment-variables vue.js vue-cli-3

12
推荐指数
2
解决办法
6348
查看次数

如何获取Vue中路线的当前名称?

我想获取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)

但是路由名称的标签不会更改,标签仅显示第一个加载的路由的名称。谢谢

编辑:

在此处输入图片说明

显示我想要的图像

vue.js vue-router

9
推荐指数
4
解决办法
8202
查看次数

使用 TerserWebpackPlugin 删除 console.log

我有一个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)

webpack

8
推荐指数
1
解决办法
3965
查看次数

axios 错误:TypeError:无法读取未定义的属性“状态”

index.js好的,如果状态代码为 ,我有一个拦截器来刷新令牌401,这工作正常,但是在登录页面中,如果我从服务器返回另一个状态代码,则页面中的消息错误不起作用,因为axios不接收A 401

\n

但如果收到401,拦截器就可以正常工作。

\n

这是有关该内容的屏幕截图。404如果没有找到用户,它会从服务器返回 a 。\n在此输入图像描述

\n

该错误与 相关Login.vue,但如果我删除axios.interceptors我的index.js“状态”中的Login.vue,它就可以正常工作。

\n

拦截器

\n
axios.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)

javascript axios

5
推荐指数
1
解决办法
2万
查看次数

如何使用 axios 中的数据填充 Vuetify Select

我需要填充一个 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)

非常感谢

html-select vue.js axios vuetify.js

4
推荐指数
1
解决办法
6093
查看次数