组件路径:/views/home/components/bottom.vue 示例:

<template>
  <div>
    <h1>底部信息</h1>
    <div>{{ copyright }} <button v-on:click="setTime">更新时间</button></div>
  </div>
</template>
<script>
export default {
  name: "bottom",
  props: ["copyright"],
  data() {
    return {};
  },
  methods: {
    setTime() {
      this.$emit('TimeNow',{'name':'china'});
    },
  },
};
</script>

组件建立在components文件夹下,传值使用props,参数是数组形式,this.$emit是触发父组件的TimeNow事件,以此来调用父组件函数getTimeNow。
使用组件示例:

<template>
  <div>
    <h1>首页</h1>
    <div>时间:{{tz}}-{{ dt }}</div>
    <bottom copyright="xxxxx 2020" v-on:TimeNow="getTimeNow"></bottom>
  </div>
</template>
<script>
import bottom from "@/views/home/components/bottom";
export default {
  name: "home",
  components: { bottom },
  data() {
    return {
      dt: null,tz:''
    };
  },
  methods: {
    getTimeNow(timeZone) {
      this.dt = new Date();this.tz=timeZone.name;
    },
  },
};
</script>

 

相关文章:

  • 2021-06-19
  • 2021-11-11
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
猜你喜欢
  • 2021-09-25
  • 2021-04-08
  • 2021-12-30
  • 2021-06-23
  • 2021-12-04
  • 2021-06-26
相关资源
相似解决方案