vue.js 引入外部的js文件

js源码:

import Vue from 'vue';

let v = new Vue();

 

function 方法一名称(message) {

v.$alert(message, "提示", {

confirmButtonText: '确定'

});

}

 

function 方法二名称(){

history.go(0);

}

showPage(){

   Alert(显示);

}

 

export {

方法一名称,方法二名称,showPage//多个方法在此处json中export出去

}

 

vue文件下的js源码:

Import  {方法一名称} from js文件路径    //引入

如:import {showPage,方法一名称,方法二名称} from '../../js/common.js'

 

export default {

data() {

return {

};

},

methods: {

//页面中的方法

方法三() {

方法一名称("我是外部js中的方法一");  //直接调用无需this.

showPage();

},

};

 

 

发布了98 篇原创文章 · 获赞 19 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/water_Popcorn/article/details/98596607