zoukankan      html  css  js  c++  java
  • Vue全局引入JS的方法

    两种情况:

    1. js为ES5的写法时,如下(自定义的my.js):

    function fun(){
        console.log('hello');      
    }
    

     Vue中的全局引入方式为,在index.html中通过如下方式引入即可:

    <script src="src/models/my.js"></script>
    

    2. js为 ES6 模块化写法时,即 import,export形式,如下:

    var fun=function(){
        console.log('hello');
    }
    export default fun;
    

     Vue中全局引入的方式为,在main.js中添加如下代码:

    import fun from 'src/models/my.js';
    Vue.prototype.$xx=fun;  //其中$xx为新命的名。
    

     使用方法为,在要调用的地方使用如下代码调用:

    var aa=this.$xx;
    

      注意,模块化引入方式时,要引入的 js export的值只可为一个,若多余一个如 export {var1,var2,...} 则不可使用这种方式 (经验证无效)。

  • 相关阅读:
    java设计模式概述
    Filter
    hello1 hello2 代码分析
    计划
    页面生命周期1
    Jquery
    关于DropDownList
    页面生命周期
    随机生成验证码
    关于技术
  • 原文地址:https://www.cnblogs.com/zhcBlog/p/9892883.html
Copyright © 2011-2022 走看看