亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

用Vue.js開發(fā)網(wǎng)頁時(shí)鐘

 更新時(shí)間:2022年08月30日 14:15:30   作者:中國胖子風(fēng)清揚(yáng)  
這篇文章主要為大家詳細(xì)介紹了用Vue.js開發(fā)一個(gè)網(wǎng)頁時(shí)鐘,分為白天模式和夜晚模式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Vue.js開發(fā)網(wǎng)頁時(shí)鐘的具體代碼,供大家參考,具體內(nèi)容如下

本次實(shí)例的重點(diǎn)是父子通信,這也是學(xué)習(xí)Vue.js的重點(diǎn)部分和難點(diǎn)部分,能掌握好父子通信是對(duì)后期的Vue學(xué)習(xí)是一個(gè)很大的幫助,而且如果不跨過這個(gè)難點(diǎn)部分,是無法進(jìn)行后期的學(xué)習(xí)的。
父子通信很好用,但是很難理解而且寫著寫著還很容易出現(xiàn)錯(cuò)誤

父子通信的重點(diǎn)知識(shí)

1、子組件通過props屬性監(jiān)聽從父組件中傳過來的值(值)
2、子組件通過$emit('方法名‘)來向父組件發(fā)出請(qǐng)求(方法)
3、學(xué)習(xí)vue必須要知道屬性只要綁定好后就是動(dòng)態(tài)的模式(我個(gè)人理解),就只需要接收和請(qǐng)求就行了,不需要做其他的監(jiān)聽操作

話不多說,上代碼

一、頁面部分

1、 創(chuàng)建模板
2、通過父子通信來對(duì)子組件的部分屬性進(jìn)行監(jiān)聽

<!DOCTYPE html>
<html lang="en">
<head>
? ? <meta charset="UTF-8">
? ? <title>Time</title>
? ? <link href="../css/index_css.css" rel="stylesheet">//采用外部連接的格式
</head>

<body>

<div id="content" class="content">
? ? <div id="over" @click="show()" :style="o_style">{{o_style.value}}</div>
? ? <clock :cur_time="current_time" @get_hour="getHours()" @get_minute="getMinutes()" @get_second="getSeconds()"
? ? ? ? ?:hour_s="hour_style" :minute_s="minute_style" :second_s="second_style" :com_s="o_style">
? ? </clock>
</div>


//模板部分
<template id="time_template">
? ? <div class="root">
? ? ? ? ? ? <span :style="{color:com_s.isNight==true?'white':'black'}">12</span>
? ? ? ? ? ? <span :style="{color:com_s.isNight==true?'white':'black'}">3</span>
? ? ? ? ? ? <span :style="{color:com_s.isNight==true?'white':'black'}">6</span>
? ? ? ? ? ? <span :style="{color:com_s.isNight==true?'white':'black'}">9</span>
? ? ? ? ? ? <span class="over-point"></span>
? ? ? ? ? ? <div id="hour" :style="hour_s"></div>
? ? ? ? ? ? <div id="minute" :style="minute_s"></div>
? ? ? ? ? ? <div id="second" :style="second_s"></div>
? ? ? ? ? ? <div id="show_time">{{cur_time.hour}}:{{cur_time.minute}}:{{cur_time.second}}</div>
? ? </div>
</template>

<script src="../external_lib/vue.js"></script>//這里是vue.js包的導(dǎo)入
<script src="../js/index_js.js"></script>//采用外部連接的格式
<script src="../js/pageControl.js"></script>//采用外部連接的格式
</body>
</html>

二、CSS部分

*{
? ? margin:0px;
? ? padding:0px;
}
body{
? ? display: flex;
? ? justify-content: center;
? ? align-items: center;
? ? align-content: center;
? ? background:skyblue;
? ? overflow: hidden;
}
#content{
? ? position:relative;
? ? width:100%;
? ? height:100vh;
? ? display:flex ;
? ? justify-content: center;
? ? align-content: center;
? ? align-items: center;
}
.root{
? ? width:500px;
? ? height:500px;
? ? border-radius: 50%;
? ? border:2px solid grey;
? ? position:relative;
? ? top:50px;
? ? background: url("../img/day.jpg") -170px;
? ? background-size:cover;
? ? overflow: hidden;
? ? box-shadow: 0px 0px 15px gray;
}

.root>span,.root>div{
? ? position:absolute;
? ? font-size:20px;/*內(nèi)部的每一個(gè)文字的大小*/
}
span:first-child{
? ? left:240px;/*十二這個(gè)數(shù)字的x偏移量=(500/2)-(20/2)*/
? ? top:10px;
? ? z-index:10;
}
span:nth-child(2){
? ? left:480px;/*3的x偏移量=(500-10)*/
? ? top:240px;/*(500/2)-(20/2)*/
? ? z-index:10;
}
span:nth-child(3){
? ? left:250px;/*6*/
? ? top:470px;
? ? z-index:10;
}
span:nth-child(4){
? ? left:10px;/*9*/
? ? top:240px;
? ? z-index:10;
}
span:nth-child(5){/*時(shí)鐘中間的骨架*/
? ? left:225px;/*(500/2)-(50/2)*/
? ? top:225px;/*(500/2)-(50/2)*/
? ? display: inline-block;
? ? width:50px;
? ? height:50px;
? ? line-height:50px;
? ? text-align: center;
? ? font-weight:bolder;
? ? border-radius: 50%;
? ? background:cadetblue;
? ? box-shadow: 0px 0px 18px #5f9ea0,inset 0px 0px 10px #4faee0;
? ? z-index:12;
}
#hour{
? ? width:20px;
? ? height:120px;
? ? border-radius:12px;
? ? background:white;
? ? top:136px;
? ? left:242px;
? ? opacity:88%;
? ? box-shadow: 0 0 18px whitesmoke;
? ? z-index:11;
}
#minute{
? ? width:15px;
? ? height:160px;
? ? border-radius:12px;
? ? background:dodgerblue;
? ? top:90px;
? ? left:243px;
? ? opacity: 0.85;
? ? box-shadow: 0 0 18px deepskyblue;
? ? z-index:11;
}
#second{
? ? width:10px;
? ? height:200px;
? ? border-radius:12px;
? ? background:gray;
? ? top:50px;
? ? left:250px;
? ? opacity:0.8;
? ? box-shadow: 0 0 18px snow;
? ? z-index:11;
}
#show_time{
? ? width:100px;
? ? height:50px;
? ? background:black;
? ? opacity:0.6;
? ? left:200px;
? ? top:300px;
? ? color:white;
? ? text-align: center;
? ? line-height:50px;
? ? z-index:10;
}
#over{
? ? position:absolute;
? ? width:100%;
? ? height:100vh;
? ? color:white;
? ? background:black;
? ? opacity: 0.8;
? ? transition:1s;
? ? z-index:10;
}

三、JS部分(重點(diǎn)部分)

父子通信

/**子組件
?* 子組件的時(shí)針、分針、秒針都是通過父組件傳過來的值來設(shè)置它的偏移量
?*/
let clock={
? ? template:'#time_template',
? ? data(){
? ? ? ? return{
? ? ? ? ? ? interval:'',//定時(shí)器對(duì)象
? ? ? ? }
? ? },
? ? props:{//監(jiān)聽從父組件中傳過來的對(duì)象
? ? ? ? cur_time: '',
? ? ? ? com_s:{},
? ? ? ? hour_s:{},
? ? ? ? minute_s:{},
? ? ? ? second_s:{},
? ? },
? ? methods:{
? ? ? ? ? ? display(){
? ? ? ? ? ? ? ? this.interval=setInterval((e)=>{
? ? ? ? ? ? ? ? ? ? this.setHours();
? ? ? ? ? ? ? ? ? ? this.setMinutes();
? ? ? ? ? ? ? ? ? ? this.setSeconds();
? ? ? ? ? ? ? ? },1000);
? ? ? ? ? ? },
? ? ? ? ? ? setHours(){
? ? ? ? ? ? ? ? this.$emit('get_hour');
? ? ? ? ? ? },
? ? ? ? ? ? setMinutes(){
? ? ? ? ? ? ? ? this.$emit('get_minute');
? ? ? ? ? ? },
? ? ? ? ? ? setSeconds(){
? ? ? ? ? ? ? ? this.$emit('get_second');
? ? ? ? ? ? },
? ? },
? ? created(){//讓方法在一開始就自動(dòng)調(diào)用,一般適用于有定時(shí)器的方法
? ? ? ? this.display();
? ? }
};

/**
?* 父組件
?*/
let fatherComponent=new Vue({
? ? el:'#content',
? ? data:{
? ? ? ? date:new Date(),
? ? ? ? current_time:{//表示當(dāng)前時(shí)間的對(duì)象
? ? ? ? ? ? hour:'',
? ? ? ? ? ? minute:'',
? ? ? ? ? ? second:'',
? ? ? ? },
?? ??? ?//需要傳給子組件的對(duì)象
? ? ? ? hour_style: {},
? ? ? ? minute_style:{},
? ? ? ? second_style:{},
? ? ? ? //頁面樣式的初始化屬性
? ? ? ? o_style:{
? ? ? ? ? ?left:'97%',
? ? ? ? ? ? isNight:false,//監(jiān)聽是白天還是黑夜,默認(rèn)是白天
? ? ? ? ? ? value:'N-M',
? ? ? ? },
? ? },
? ? //通過子組件向父組件發(fā)起請(qǐng)求的方法
? ? methods:{
? ? ? ? getHours(){
? ? ? ? ? ? this.date=new Date();
? ? ? ? ? ? this.current_time.hour=this.date.getHours()>=10?this.date.getHours():'0'+this.date.getHours();
? ? ? ? ? ? let hour=this.date.getHours()%12+(this.date.getMinutes()+(this.date.getSeconds()/60)/60);
? ? ? ? ? ? this.hour_style={
? ? ? ? ? ? ? ? transformOrigin:'bottom center',
? ? ? ? ? ? ? ? transform:'rotate('+this.date.getHours()*30+'deg)',
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? getMinutes(){
? ? ? ? ? ? this.date=new Date();
? ? ? ? ? ? this.current_time.minute=this.date.getMinutes()>=10?this.date.getMinutes():'0'+this.date.getMinutes();
? ? ? ? ? ? let m=this.date.getMinutes();
? ? ? ? ? ? this.minute_style={
? ? ? ? ? ? ? ? transformOrigin:'bottom center',
? ? ? ? ? ? ? ? transform:'rotate('+(m*6)+'deg)',//分為六十等分,每份為一分鐘
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? getSeconds(){
? ? ? ? ? ? this.date=new Date();
? ? ? ? ? ? this.current_time.second=this.date.getSeconds()>=10?this.date.getSeconds():'0'+this.date.getSeconds();
? ? ? ? ? ? this.second_style={
? ? ? ? ? ? ? ? transformOrigin:'bottom center',
? ? ? ? ? ? ? ? transform:'rotate('+this.date.getSeconds()*6+'deg)',//將圓分為六十份,每份為一秒鐘。
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? //對(duì)頁面對(duì)象的屬性進(jìn)行修改
? ? ? ? show(){
? ? ? ? ? ? if(this.o_style.isNight){
? ? ? ? ? ? ? ? this.o_style.left='97%';
? ? ? ? ? ? ? ? this.o_style.isNight=false;
? ? ? ? ? ? ? ? this.o_style.value='N-M'
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? this.o_style.left='0%';
? ? ? ? ? ? ? ? this.o_style.isNight=true;
? ? ? ? ? ? ? ? this.o_style.value='D-M'
? ? ? ? ? ? }
? ? ? ? }
? ? },
? ? //在父組件內(nèi)聲明子組件,這是必須的
? ? components:{
? ? ? ? clock
? ? }
});

四、效果圖

白天模式:

在白天模式中,單擊N-M層就能變成夜間模式

夜晚模式:

在夜晚模式中單擊任何地方都可以變回白天模式
夜晚模式中每個(gè)指針都是發(fā)光的

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue-cli3項(xiàng)目在IE瀏覽器打開兼容問題及解決

    vue-cli3項(xiàng)目在IE瀏覽器打開兼容問題及解決

    這篇文章主要介紹了vue-cli3項(xiàng)目在IE瀏覽器打開兼容問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • 詳解解決Vue相同路由參數(shù)不同不會(huì)刷新的問題

    詳解解決Vue相同路由參數(shù)不同不會(huì)刷新的問題

    這篇文章主要介紹了詳解解決Vue相同路由參數(shù)不同不會(huì)刷新的問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-10-10
  • Vue子組件調(diào)用父組件事件的3種方法實(shí)例

    Vue子組件調(diào)用父組件事件的3種方法實(shí)例

    大家在做vue開發(fā)過程中經(jīng)常遇到父組件需要調(diào)用子組件方法或者子組件需要調(diào)用父組件的方法的情況,這篇文章主要給大家介紹了關(guān)于Vue子組件調(diào)用父組件事件的3種方法,需要的朋友可以參考下
    2024-01-01
  • LogicFlow內(nèi)置菜單插件實(shí)例詳解

    LogicFlow內(nèi)置菜單插件實(shí)例詳解

    這篇文章主要為大家介紹了LogicFlow內(nèi)置菜單插件實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • Element樹形控件整合帶圖標(biāo)的下拉菜單(tree+dropdown+input)

    Element樹形控件整合帶圖標(biāo)的下拉菜單(tree+dropdown+input)

    Element UI 官網(wǎng)提供的樹形控件包含基礎(chǔ)的、可選擇的、自定義節(jié)點(diǎn)內(nèi)容的、帶節(jié)點(diǎn)過濾的以及可拖拽節(jié)點(diǎn)的樹形結(jié)構(gòu),本文實(shí)現(xiàn)了樹形控件整合帶圖標(biāo)的下拉菜單,感興趣的可以了解一下
    2021-07-07
  • Vue.js實(shí)現(xiàn)日歷功能

    Vue.js實(shí)現(xiàn)日歷功能

    這篇文章主要為大家詳細(xì)介紹了Vue.js實(shí)現(xiàn)日歷功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Vue中的組件注冊(cè)方法及注意事項(xiàng)

    Vue中的組件注冊(cè)方法及注意事項(xiàng)

    在Vue中,組件是構(gòu)建頁面的基本單位。通過組件化開發(fā),可以提高代碼的復(fù)用性和可維護(hù)性。組件的注冊(cè)方法包括全局注冊(cè)和局部注冊(cè)兩種方式。同時(shí),需要注意組件名的命名規(guī)范、組件選項(xiàng)的定義方式、組件之間的通信等問題,以實(shí)現(xiàn)更好的組件復(fù)用和開發(fā)效率
    2023-05-05
  • 在Vue項(xiàng)目中用fullcalendar制作日程表的示例代碼

    在Vue項(xiàng)目中用fullcalendar制作日程表的示例代碼

    這篇文章主要介紹了在Vue項(xiàng)目中用fullcalendar制作日程表,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • vue3?身份證校驗(yàn)、識(shí)別性別/生日/年齡的操作代碼

    vue3?身份證校驗(yàn)、識(shí)別性別/生日/年齡的操作代碼

    這篇文章主要介紹了vue3?身份證校驗(yàn)、識(shí)別性別/生日/年齡的操作代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),表單項(xiàng)綁定 @change 事件,?定義身份驗(yàn)證規(guī)則規(guī)則,感興趣的朋友跟隨小編一起看看吧
    2024-07-07
  • vue 微信分享回調(diào)iOS和安卓回調(diào)出現(xiàn)錯(cuò)誤的解決

    vue 微信分享回調(diào)iOS和安卓回調(diào)出現(xiàn)錯(cuò)誤的解決

    這篇文章主要介紹了vue 微信分享回調(diào)iOS和安卓回調(diào)出現(xiàn)錯(cuò)誤的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09

最新評(píng)論