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