所以我对此真的Vue.js很陌生,我想要实现的目标很简单,我正在尝试将此Ajax请求的结果附加到我的列表中
<div id="app">
<button v-on:click="buttonClick">Test</button>
<ul id="example-1">
<li v-for="t in test">
{{ t }}
</li>
</ul>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
'message': 'hello world',
'test': null
},
methods: {
buttonClick: function() {
axios.get('api/getdata')
.then(function(response) {
test = response.data;
//if this was Jquery I'd use $('li').append here
})
.catch(function(error) {
});
}
}
})
</script>
Run Code Online (Sandbox Code Playgroud)
现在的问题是我不知道该怎么做,我的变量test应该保存所有数据,然后我应该像我一样循环它,但是一旦我得到数据,我如何再次触发它?
编辑:澄清一下,我不是在问关于“this”和“self”的问题,我问的是如何将这些数据附加到一些 HTML 元素上
vue.js ×1