What is Vue way to access to data from methods?

后端 未结 3 1154
攒了一身酷
攒了一身酷 2021-02-01 12:12

I have the following code:

{
  data: function ()  {
    return {
      questions: [],
      sendButtonDisable: false,
    }
  },

  methods: { 
    postQuestions         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 12:36

    It depends on how you call your postQuestionsContent method (if you call it asynchronously, you might need to bind the this context).

    In most cases, you should be able to access it using this.$data.YOURPROPNAME, in your case this.$data.sendButtonDisable:

    data: function ()  {
      return {
         questions: [],
         sendButtonDisable : false
      }
    
      },
    
      methods: 
      { 
         postQuestionsContent : function()
         {
            this.$data.sendButtonDisable = true;
         }
      }
    

提交回复
热议问题