剛學不久,有事請教
data 出來是這樣
data = {"message":"hello","name":"peter","age":"30"}
怎樣才可把DATA 放進去TEXTAREA??
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
{% verbatim %}
<div id="div1">
<el-input type="textarea" :rows="2" placeholder="Please input" v-model="principal_message"></el-input>
<el-button @click="save">save</el-button>
</div>
</div>
<script>
new Vue({
el: "#div1",
data() {
return {
activeName: 'first',
tableData: [],
input: '',
principal_message: '',
data: [{"message":"hello","name":"peter","age":"30"}],
}
},
async created() {
let { data } = await this.$http.get(window.location.pathname + "/getData");
// data = {"message":"hello","name":"peter","age":"30"}
},
methods: {
save() {
this.$http.post("", this.data);
console.log(this.data);
}
}
});
</script>
{% endverbatim %}
怪事,這麼簡單的題沒人要答...
async created() {
// await會讓程式等待到GET一定會有回應,另外建議實際生產的code應該檢查一下回傳的 http status code,並加入錯誤檢測
let { data } = await this.$http.get(window.location.pathname + "/getData");
// 我不知道你接回來是什麼格式,如果你接回來是字串,直接像下面這樣就行了
this.principal_message = data
// data不是字串的話,請自己用 JSON.stringify(data) 替換掉
},