Vue.js làm sao set cái data

em mới học vue.js mong anh em chỉ giáo


<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div id="app">
    <p>{{ message }}</p>
    <button v-on:click="javascript:alert('hello world');" >test hello</button> <br />
    <button v-on:click="greet();">test hello2</button> <br />
    <button v-on:click="greet2();">test hello3</button> <br />
</div>


<script>

    new Vue({

        el: '#app',
        data: {
            message: 'Hello Vue.js!'
        },
        methods: {
            greet: function (e) {
                alert('hello world')
            },
            greet2: function (e) {
                this.data.message = "hello world 3";//Sao cái này không chạy???
            }
        }

    })


</script>



dòng trên thay bằng

  this.message = "hello world 3";
2 Likes

wow , thank a ton!!!
Đơn giản thế thôi sao.

không phải đơn giản thế thôi sao là xong đâu bạn, bạn nên đọc kĩ document của Vue.js trước khi đụng đến 1 phần nào đó để tránh những lỗi cú pháp đơn giản:
link: https://vuejs.org/

2 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?