<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>轮播图</title>
<style>
.img {
width: 495px;
height: 212px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="app">
<div class="img" :style="imgUrl">
</div>
</div>
<script src="vue.js"></script>
<script>
var vm = new Vue({
el: "#app",
data: {
index: 0,
imgUrl: {
"background-image": " url(img/banner1.jpg)"},
},
mounted() {
var _this = this
setInterval(function () {
_this.imgUrl = {
"background-image": " url(img/banner" + (_this.index%4+1) + ".jpg)"
}
_this.index++
}, 1000)
}
})
</script>
</body>
</html>