vue-引入外部js文件的方法和常量


1、方法调用 

a:  js文件(static/js/public.js)

//函数的定义  返回上一页
export function goback(laststep) { 
  laststep
} 

b: 调用

import {goback} from 'static/js/public.js'//记得带上{}花括号

methods:{
    _goback(){
        goback(this.$router.go(-1));
    }

}

<span class="gobakc" @click="_goback"></span>    

2、常量引用  

a:文件 static/js/publicstate.js

const staticimg='../../../../static/images/';
export default
  {
  staticimg, 

  }  

b: import commonstate from 'static/js/publicstate.js'//引用模块进来

data(){
    return {
        imgsrc:commonstate.staticimg,
    }
}

 <p>wrww{{imgsrc}}</p>

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM