美文网首页
vue局部引入外部js方法

vue局部引入外部js方法

作者: zkzhengmeng | 来源:发表于2019-07-18 08:21 被阅读0次

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方法
            }
        }
    }

相关文章

网友评论

      本文标题:vue局部引入外部js方法

      本文链接:https://www.haomeiwen.com/subject/xaxklctx.html