vue中引入自定义的js文件

  • Post author:
  • Post category:vue




1.创建utils/index.js文件

其结构如下:

import { Toast } from ‘mint-ui’;

function Toasts (text){ //mint-ui

Toast({


message: text,

position: ‘middle’,

className:‘toastclass’,

duration: 2000

});

}

function urllist(){


var url = “

http://www.diniver.com/index/

”;

return url;

}

function urllist2(){


var url = “

http://www.diniver.com/index/

”;

return url;

}

export { //返回函数模块

Toasts,

urllist,

urllist2,

}



2. main.js中引用

import {urllist, Toasts} from ‘./utils/index.js’ //导入自定义函数

Vue.prototype.



u

r

l

l

i

s

t

=

u

r

l

l

i

s

t

/

/

v

u

e

V

u

e

.

p

r

o

t

o

t

y

p

e

.

urllist = urllist //把自定义函数挂载到vue原型 Vue.prototype.






u


r


l


l


i


s


t




=








u


r


l


l


i


s


t


/


/





























v


u


e








V


u


e


.


p


r


o


t


o


t


y


p


e


.





toasts = Toasts



3. 子组件中调用

this.$urllist()



版权声明:本文为weixin_43886668原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。