文字动起来

//记得引入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>

猜你喜欢

转载自www.cnblogs.com/kangkang-saonian/p/10284533.html