vue翻转字符串
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div id="app">
<button @click="fn">翻转</button>
<p>{{ msg }}</p>
</div>
<script src="./vue.js"></script>
<script>
const vm = new Vue({
el: '#app',
data: {
msg: 'hello vue'
},
methods: {
fn () {
this.msg = this.msg.split('').reverse().join('')
}
}
})
</script>
</body>
</html>
vue跑马灯案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div id="app">
<button @click="run">跑</button>
<button @click="stop">停</button>
<p>{{ msg }}</p>
</div>
<script src="./vue.js"></script>
<script>
const vm = new Vue({
el: '#app',
data: {
msg: '猪肉30一斤,买一斤送一斤',
timeId:''
},
methods: {
run () {
if(this.timeId) return
this.timeId = setInterval(() => {
this.msg = this.msg.slice(1) + this.msg.slice(0,1)
},500)
},
stop () {
clearInterval(this.timeId)
this.timeId = ''
}
}
})
</script>
</body>
</html>
来源:CSDN
作者:Pray_for_xi
链接:https://blog.csdn.net/Pray_for_xi/article/details/103809125