文字動起來

//記得引入vue文件!!!
<div id="app">
        <button @click='start'>讓你動起來</button>
        <button @click='end'>停下來哈</button>
        <p>{{mesg}}</p>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                mesg: "小白你好,你還在入門階段",
                timerId:null
            },
            methods: {
                start() {
                    clearInterval(this.timerId)
                   this.timerId= setInterval(()=>{
                        let start = this.mesg.substr(0, 1);
                        let end = this.mesg.substr(1);
                        this.mesg = end + start;
                    },200)
                },
                end() {
                    clearInterval(this.timerId)
                }
            }
        })
    </script>
相關文章
相關標籤/搜索