简体   繁体   English

如何在quasar框架中声明package.json文件中的变量并在vue中显示?

[英]How do I declare the variable in the package.json file in the quasar framework and show it in vue?

I want to declare a variable in package.json and route according to the variable.我想在package.json中声明一个变量,并根据变量进行路由。

// package.json

  "scripts": {

    "electron:build:HI": "cross-env example=HI quasar dev -m electron -d",
    "electron:build:HELLO": "cross-env example=HELLO quasar dev -m electron -d",

  },
// routes.js
...
const route = [
      {
        path: 'document-before-billA',
        component: () => process.env.example === 'HI' ? import(`@/pages/documentDownload/DocumentBeforeBill${example}.vue`) : ''
      },
      {
        path: 'document-before-billB',
        component: () => process.env.example === 'HELLO' ? import(`@/pages/documentDownload/DocumentBeforeBill${example}.vue`) : ''
      }
]

I've tried cross-env, but it doesn't work.我已经尝试过 cross-env,但它不起作用。 Is there a way to dynamically allocate it in quasar.config.js?有没有办法在quasar.config.js中动态分配? Please let me know if you can use another library.如果您可以使用其他图书馆,请告诉我。

I solved it.我解决了。

...
  "scripts": {
    "electron:build:HI": "cross-env example=HI quasar dev -m electron -d",
  },
...
quasar.config.js
...
env : {
 example: process.env.example
}
...

it work !这行得通 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM