<script type="text/x-template" id="modeProgram">
<div>
<div class="calendar">
<ul class="day header">
<li class="dayList" v-for="(m, index) in 7" v-bind:key="m.index" v-text="getWeekdayText(m)"></li>
</ul>
<div class="day content">
<router-link tag="div" to="" class="dayList" v-bind:class=" m == 12 ? 'g' : null || m == 28 ? 'r' : null " v-for="(m, index) in 42" v-bind:key="index">
<transition name="opacity" mode="out-in">
<div class="text" v-if=" generateCalendar({method:'query',index:m}) ">
<p v-for="l in 3">21391232103809f9dsiljlaksdjlkkl</p>
</div>
</transition>
<transition name="opacity" mode="out-in">
<div class="num" v-text=" generateCalendar({method:'get',index:m}) "></div>
</transition>
</router-link>
</div>
</div>
<div class="snyc">
<div class="title" v-on:click="miao = !miao">
<span>同步與記錄</span>
<span class="icon-more" v-bind:class="{av:miao}">
<span></span>
<span></span>
</span>
</div>
<transition name="opacity" mode="out-in">
<div v-if="miao">
<div class="herader">
<div class="tap">設備</div>
<div class="tap">歷史記錄</div>
</div>
<ul class="list">
<li class="content">
<div class="select">
<input />
</div>
<div class="images">圖片</div>
<div class="name">名字</div>
<div class="downloading">下載</div>
<div class="fn">操作</div>
</li>
<li class="content">
<div class="select">
<input />
</div>
<div class="images">
</div>
<div class="name"></div>
<div class="downloading"></div>
<div class="fn">
<button>刪除</button>
</div>
</li>
<li class="content">
<div class="select"></div>
<div class="images"></div>
<div class="name"></div>
<div class="downloading"></div>
<div class="fn">
<button>添加</button>
</div>
</li>
</ul>
</div>
</transition>
</div>
</div>
</script>
<script>
Vue.component('mode-program', {
template:'#modeProgram',
data (){
return{
Date:{
year:null,
month:null
},
miao:true
}
},
computed:{
details () {
return store.state.details.data
},
nowYear(){
return this.Date.year
},
nowMonth(){
return this.Date.month+1
}
},
watch:{
'Date.year':function () {
window.dayNum = 0
},
'Date.month':function () {
window.dayNum = 0
}
},
created (){
window.dayNum = 0
this.setDate();
},
mounted (){
},
methods:{
setDate(){
let time = new Date()
this.Date.year = time.getFullYear()
this.Date.month = time.getMonth()
},
lastMonth:function () {
if ( this.Date.month <= 0 ){
this.Date.month = 11;
this.lastYear();
}else {
--this.Date.month;
}
},
nextMonth:function () {
if ( this.Date.month >= 11 ){
this.Date.month = 0;
this.nextYear();
}else {
++this.Date.month;
}
},
lastYear:function () {
this.Date.year <= 1970 ? this.Date.year = 1970 : --this.Date.year
},
nextYear:function () {
++this.Date.year
},
getWeekdayText:function(m) {
let text
if (m == 1){ text = '一' }
if (m == 2){ text = '二' }
if (m == 3){ text = '三' }
if (m == 4){ text = '四' }
if (m == 5){ text = '五' }
if (m == 6){ text = '六' }
if (m == 7){ text = '日' }
return text
},
generateCalendar:function(s) {
let method = s.method
let time = new Date().setFullYear(this.Date.year != null ? this.Date.year : '',this.Date.month != null ? this.Date.month : '',1)
let day = new Date( time ).getDate()
let month = this.Date.month != null ? new Date( time ).getMonth() : new Date().getMonth()
let year = this.Date.year != null ? new Date( time ).getFullYear() : new Date().getFullYear()
let weekDay = this.Date.year != null ? new Date( time ).getDay() : new Date().getDay()
weekDay == 0 ? weekDay = 7 : weekDay
let index = s.index ? s.index : 0
let isLeapYear = year % 4 == 0 ? [31,29,31,30,31,30,31,31,30,31,30,31] : [31,28,31,30,31,30,31,31,30,31,30,31]
let e = {
1:[3,5,1,10,17,21],
2:[7,11,16],
3:[9,22,30]
}
if ( s.index >= weekDay && window.dayNum < isLeapYear[month] ){
if ( method === 'query' ){
return true
}
if ( method === 'get' ){
window.dayNum = ++window.dayNum
return window.dayNum
}
}
}
}
})
</script>
當我更改里面的miao的時候,calendar里面的getWeekdayText()和generateCalendar()會被重新調(diào)用,為什么會這樣?
經(jīng)實驗,v-if和v-show都有影響
在開關下面同步與記錄的時候下面日期的東西就會消失
經(jīng)過幾個小時的整理,終于找到了問題所在,雖然為什么更改那個狀態(tài)會觸發(fā)那個函數(shù)還未琢磨透,不過暫時這個方法是可行的,鏈接地址:https://jsfiddle.net/luozz/d4...
注意那個generateCalendar
函數(shù)的后幾行便可,其它的你可以參考,就稍微優(yōu)化了一下,沒有具體去修改其它代碼,只是為了找到問題所在而進行的各種嘗試。
問題出現(xiàn)在了window.dayNum
未在函數(shù)執(zhí)行完成之后進行置0
,導致下一次觸發(fā)函數(shù)保存的數(shù)值是上一次執(zhí)行函數(shù)的最終值
希望我的回答能幫助你找到問題所在! ^_^
謝邀,這很正常,你這是“一個”組件,這個組件依賴 miao
,所以 miao
變了整個組件必然跑一遍更新周期。不希望被調(diào)用就需要提示 vue 這里不需要更新,
北大青鳥APTECH成立于1999年。依托北京大學優(yōu)質雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學院和江蘇省首批服務外包人才培訓基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術與教育服務機構,發(fā)展為教育服務業(yè)的綜合性企業(yè)集團,成為集合面授教學培訓、網(wǎng)
達內(nèi)教育集團成立于2002年,是一家由留學海歸創(chuàng)辦的高端職業(yè)教育培訓機構,是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責任公司從事總經(jīng)理職務負責iOS教學及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術, 熟練的跨平臺面向對象開發(fā)經(jīng)驗,技術功底深厚。 授課風格 授課風格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術顧問,美國Dachieve 系統(tǒng)架構師,美國AngelEngineers Inc. 系統(tǒng)架構師。