/src/route/index.js import Demo2 from ‘@/pages/demo2/index.vue‘ { path : ‘/demo2‘, name : ‘demo2‘, component: Demo2 }, /src/pages/demo1/index.vue <template> <div> <div>自定义组件</div> <div>--------------------</div> <countdown></countdown> </div> </template> <script> import countdown from ‘@/components/countdown.vue‘ export default{ data(){ return { } }, components : { countdown }, } </script> /src/components/countdown.vue <template> <p>{{time}}</p> </template> <script> export default{ data(){ return { time: 10, } }, mounted : function(){ let vm = this; let t = setInterval(function(){ vm.time--; if(vm.time == 0){ clearInterval(t); vm.$emit(‘end‘); } },1000) } } </script>
原文地址:https://www.cnblogs.com/cl94/p/12216025.html
时间: 2024-11-07 08:22:10