文字动起来

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

 

posted @ 2019-01-17 20:59  小金king  阅读(114)  评论(0编辑  收藏  举报