<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>事件处理</title>
<style type="text/css">
div>div{
width: 128px;
height: 128px;
}
</style>
</head>
<body>
<div id="app">
<p>鼠标位于({{x}},{{y}})</p>
<p>背景色{{backgroundColor}}</p>
<div v-on:mousemove="mousemove" v-bind:style="{backgroundColor}"></div>
</div>
<script src="../js/vue.js"></script>
<script>
let vm = new Vue({
el:'#app',
data:{
x:0,
y:0,
},
methods:{
mousemove:function (event) {
this.x = event.offsetX;
this.y = event.offsetY;
}
},
computed:{
backgroundColor(){
const c = (this.x + this.y).toString(16);
return c.length == 2 ? `#${c}${c}${c}`:`#0${c}0${c}0${c}`;
}
}
});
</script>
</body>
</html>
vue-前端第5章event06.html
原创
©著作权归作者所有:来自51CTO博客作者虾米大王的原创作品,请联系作者获取转载授权,否则将追究法律责任

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
vue-前端第5章event11.html
【代码】vue-前端第5章event11.html。
javascript html css 修饰符 -
vue-前端第5章event14.html
【代码】vue-前端第5章event14.html。
vue.js javascript 前端 html Vue -
vue-前端第5章event02.html
【代码】vue-前端第5章event02.html。
vue.js javascript 前端 html Vue -
vue-前端第5章event05.html
【代码】vue-前端第5章event05.html。
vue.js javascript 前端 html Vue -
vue-前端第5章event03.html
【代码】vue-前端第5章event03.html。
vue.js javascript 前端 html Vue -
vue-前端第5章event12.html
【代码】vue-前端第5章event12.html。
javascript css html bc -
vue-前端第5章event04.html
【代码】vue-前端第5章event04.html。
vue.js javascript 前端 html Vue -
vue-前端第5章event01.html
【代码】vue-前端第5章event01.html。
vue.js javascript 前端 html Vue -
vue-前端第5章event10.html
【代码】vue-前端第5章event10.html。
javascript css html 修饰符 -
vue-前端第5章event09.html
【代码】vue-前端第5章event09.html。
javascript html css 修饰符 -
vue-前端第5章event13.html
【代码】vue-前端第5章event13.html。
javascript css html 修饰符 提交表单 -
vue-前端第5章event08.html
【代码】vue-前端第5章event08.html。
javascript css html 修饰符 -
vue-前端第5章event07.html
【代码】vue-前端第5章event07.html。
javascript html css bc -
vue-前端第5章event00.html
【代码】vue-前端第5章event00.html。
javascript 前端 java html 事件流 -
vue-前端第3章watch06.html
【代码】vue-前端第3章watch06.html。
vue.js javascript 前端 html Math -
vue-前端第6章form06.html
【代码】vue-前端第6章form06.html。
vue.js javascript 前端 html 复选框 -
vue-前端第4章class06.html
【代码】vue-前端第4章class06.html。
javascript vue.js 前端 html css -
vue-前端第2章instance06.html
【代码】vue-前端第2章instance06.html。
vue.js javascript 前端 html ci -
vue-前端第7章v-if06.html
【代码】vue-前端第7章v-if06.html。
vue.js javascript 前端 html Vue