在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ mounted中加載的函數(shù)為什么在初始化之后就無法調(diào)用了?

mounted中加載的函數(shù)為什么在初始化之后就無法調(diào)用了?

如題,在mounted中初始化SimpleCalendar通過getSelectedDay()函數(shù)獲取了一個(gè)初值,然后在之后進(jìn)行按鍵響應(yīng)重新獲取這個(gè)值的時(shí)候SimpleCalendar就失效了,為什么呢?怎么解決?
【content.vue】

<template>
  <div id="content" style="font-family:微軟雅黑">
    <br><br>{{selectdate}}
    <div>
      <div  id="container" v-on:click="select"></div>
    </div>
  </div>
</template>

<script>
import  SimpleCalendar from '../js/simple-calendar'
import  '../css/simple-calendar.css'

export default {
  name:'con',
  data() {
    return {
      selectdate:''
    }
  },
  mounted:function(){
  this.$nextTick(()=>{
    //在頁面掛在之后初始化js函數(shù)
   var myCalendar = new SimpleCalendar('#container');
   //獲取初始選擇日期
   this.selectdate=myCalendar.getSelectedDay()+1;
 })
  },
  watch:{
    function(){
      //this.date=myCalendar.getSelectedDay()+1;
    }
  },
  methods:{
    select:function(){
    this.date=myCalendar.getSelectedDay()+1;
    }/*,
    callback:function(val){
      this.date=val;
    }*/
  },
  updated:function(){

  }
}
</script>

<style>
</style>

methods中 this.date=myCalendar.getSelectedDay()+1;這行代碼注釋的時(shí)候
圖片描述
未注釋的時(shí)候
圖片描述

回答
編輯回答
墻頭草

myCalendar作用域的問題。把myCalendar掛到this上。
還有,寫代碼要格式化。

export default {
  name:'con',
  data () {
    return {
      selectdate: '',
      myCalendar: null
    }
  },
  mounted () {
    this.$nextTick(()=>{
      this.myCalendar = new SimpleCalendar('#container');
      this.selectdate = this.myCalendar.getSelectedDay()+1;
    })
  },
  methods: {
    select () {
      this.selectdate=this.myCalendar.getSelectedDay()+1;
    }
  }
}
2017年9月28日 15:40
編輯回答
懶豬

select函數(shù)里面沒定義myCalendar啊。。。

2018年2月3日 11:43
編輯回答
膽怯

可能是掛在時(shí)序問題

2017年1月17日 17:50
編輯回答
雨萌萌

多看看js基礎(chǔ)知識(shí)

2017年6月11日 06:53