vue局部引入外部js方法
2019-07-18 本文已影响0人
zkzhengmeng
1 . 新建getTome.js文件
function GetDateTime() {
var date = new Date();
var seperator1 = "-";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate(); //
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate;
}
export default {
GetDateTime
}
2.新建home.vue页面
<template>
<div class="hello">
<h3 @click="getData">这个是home页面</h3>
</div>
</template>
<script>
//导入需要引入的js文件
import GetDateTime from './getData.js' //(路径根据js所在路径填写)
export default {
name: "hello",
data(){
return{
num:'12'
}
},
methods: {
getData() {
console.log(GetDateTime .GetDateTime()) //调用外部js方法
}
}
}