vue中全局、局部引入js文件【vue】、【uniapp】
vue和uniapp中引入js文件一、全局引入1、main.js当中引入// 引入个人定义js文件import * as tools from './common/util/faser/useage.js'// 自定义toolsVue.prototype.$tools=tools;2、在vue文件中引用:{{$tools.getDateTime()}}this.$tools.getDateTime
·
vue和uniapp中引入js文件
一、全局引入
1、main.js当中引入
// 引入个人定义js文件
import * as tools from './common/util/faser/useage.js'
// 自定义tools
Vue.prototype.$tools=tools;
2、在vue文件中引用:
{{$tools.getDateTime()}}
this.$tools.getDateTime()
3、工具类文件必须遵循格式:export function
useage.js中:
// 获取当天时间 日期。
export function getDateTime() {
let tmp = new Date();
let str = tmp.getFullYear() + '-' + tmp.getMonth()+1 + '-' + tmp.getDate() + ' ' + tmp.getHours() + ':' + tmp.getMinutes() + ':' + tmp.getSeconds()
return str
}
4、效果:
二、局部引入
1、vue文件当中
<script>
import * as tools from './common/util/faser/useage.js'
export default {
……
2、使用
{{tools.getDateTime()}}
this.tools.getDateTime()
更多推荐
已为社区贡献17条内容
所有评论(0)