• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Vue引用public的js文件

武飞扬头像
mini韦
帮助3

背景

由于一些演示,需要对一些简单页面进行配置,由于打包build后的vue项目基本已经看不出原样,因此需要创建一个文件,并在打包的时候不会进行编译。所以文件放在public。

步骤 

1.在public文件夹下创建config.js文件 用window.config 这样方式挂载也是可以的,或者直接定义变量。

  1.  
    let config = [
  2.  
    // window.config = [
  3.  
    {
  4.  
    title: '智能指挥中心1',
  5.  
    content: [
  6.  
    {
  7.  
    labe: '全视通(包含商事可视化)',
  8.  
    url: 'http://www.百度.com/'
  9.  
    },
  10.  
    {
  11.  
    labe: '任务处置',
  12.  
    url: 'http://www.百度.com/'
  13.  
    },
  14.  
    {
  15.  
    labe: '指挥调度',
  16.  
    url: 'http://www.百度.com/'
  17.  
    },
  18.  
    {
  19.  
    labe: '应急管理',
  20.  
    url: 'http://www.百度.com/'
  21.  
    }
  22.  
    ]
  23.  
    }
  24.  
     
  25.  
     
  26.  
     
  27.  
    ];
学新通

2.在public文件夹html文件下,使用<scrtipt>标签进入。

  1.  
    <!DOCTYPE html>
  2.  
    <html lang="en">
  3.  
    <head>
  4.  
    <meta charset="utf-8" />
  5.  
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6.  
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
  7.  
    //通过script引用
  8.  
    <script src="config.js"></script>
  9.  
     
  10.  
    <link rel="icon" href="<%= BASE_URL %>favicon.ico" />
  11.  
    <title>scw-cli</title>
  12.  
    </head>
  13.  
    <body>
  14.  
    <noscript>
  15.  
    <strong
  16.  
    >We're sorry but scw-cli doesn't work properly without JavaScript
  17.  
    enabled. Please enable it to continue.</strong
  18.  
    >
  19.  
    </noscript>
  20.  
    <div id="app"></div>
  21.  
    <!-- built files will be auto injected -->
  22.  
    </body>
  23.  
    </html>
学新通

3 直接用

  1.  
    export default {
  2.  
    name: 'Home',
  3.  
     
  4.  
    data() {
  5.  
    return {
  6.  
    loading: false,
  7.  
    data: config
  8.  
    // data: window.config //两种方式都可以
  9.  
    };
  10.  
    },
  11.  
    methods: {
  12.  
    go(url) {
  13.  
    window.open(url);
  14.  
    console.log(config);
  15.  
    }
  16.  
    }
  17.  
    };
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhffjgaf
系列文章
更多 icon
同类精品
更多 icon
继续加载