2017-11-28 6 views
0

テキストエリアに結合していないが、私は、テキストエリアに結果をバインドすることはできません:成功の内側に... axios要求は、任意のライフサイクルフックまたは任意のメソッド内であることを推測データは、私はVueのを使用しています

<textarea class="form-control" id="test" rows="6" v-model="test"></textarea> 

    data: { 
    test: '' 
    } 

      axios({ 
      method: 'post', 
      url: 'http://localhost/test, 
      responseType: 'json', 
      data: { 
       data: this.test 
      } 
      }).then(function (response) { 
      this.test= response.data 
      }).catch(function (error) { 
      console.log(error) 
      }); 
+0

VUEのインスタンスを指しているので、 ? – C2486

答えて

0

thisをコールバックがvueインスタンスを指していないため、データプロパティを変更できません。

代わりに矢印の機能を使用します。

axios({ 
      method: 'post', 
      url: 'http://localhost/test, 
      responseType: 'json', 
      data: { 
       data: this.test 
      } 
      }).then((response) => { 
      this.test= response.data 
      }).catch((error) => { 
      console.log(error) 
      }); 

脂肪の矢印機能=>バインドthisを辞書的に、あなたはthisあなたは `test`が初期化された完全な詳細を提供していない

関連する問題