首页 技术 正文
技术 2022年11月7日
0 收藏 746 点赞 233 浏览 2771 个字

(腾讯课堂学习小demo:https://ke.qq.com/course/256052)

一、简单的指令应用 ——打击灭火器

图片素材点击腾讯课堂的链接获取

Vue-小demo、小效果 合集(更新中…)Vue-小demo、小效果 合集(更新中…)     Vue-小demo、小效果 合集(更新中…)

html:

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="xing.org1^-^">
<title>敲烂灭火器</title>
<link rel="stylesheet" href="style.css" rel="external nofollow" >
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
<div class="img-box" v-bind:class="{imgburst:ended}"></div>
<div v-show="!ended">生命值剩余:{{health}} %</div>
<div v-show="ended">你赢了!</div>
<div class="progress">
<div class="progress-child" v-bind:style="{width: health + '%'}"></div>
</div>
<div class="button-box">
<button class="btn1" v-on:click="blow" v-bind:class="{disabled: ended}" >使劲敲</button>
<button v-on:click="restart">重新开始</button>
</div>
</div>
<script src="vueJson.js"></script>
</body>
</html>

html

总结:
v-bind:class的后边,是一个对象,返回布尔值!!!
并且,绑定的class样式名,不能有中横线链接符,比如:img-brust,这种会导致vue解析错误

css:

 /*京东初始化*/
* {
margin:;
padding:;
font-family: "微软雅黑"
}
em,i {
font-style: normal
}
li {
list-style: none
}
img {
border:;
vertical-align: middle
}
button {
cursor: pointer
}
a {
color: #666;
text-decoration: none
}
a:hover {
color: #c81623
}
div{
text-align: center;
margin-bottom: 5px;
}
.img-box{
width: 200px;
height: 539px;
margin: 0 auto;
background: url("img/bag.png") no-repeat;
}
.imgburst{
background: url("img/bag-burst.png") no-repeat;
}
.progress{
width: 200px;
height: 20px;
margin: 0 auto;
overflow: hidden;
background: #fff;
border-radius: 5px;
border: 2px solid red;
}
.progress-child{
width: 100px;
height: 20px;
background: red;
}
.button-box{
width: 213px;
margin: 20px auto;
overflow: hidden;
}
button{
padding: 10px 20px;
margin-left: 10px;
border-radius: 5px;
border: 1px solid #999;
background: #e5ffc9;
}
button:hover,button:focus{
outline: none;}
button:hover{
background: #4488ff;
border-color: #4488ff;
color: #fff;
}
.btn1:hover{
background: red;
border-color: red;
}
button.disabled{
cursor: not-allowed;
background: #999
}

css

Vue.js:

 new Vue({
el: "#app",
data: {
health: 100,
ended: false
},
methods: {
blow: function(){
this.health -= 10;
if(this.health <= 0){
this.ended = true;
this.health = 0
}
// console.log(this.health,this.ended)
},
restart: function(){
this.health = 100;
this.ended = false;
// console.log(this.health,this.ended)
}
}
})

Vue实例

注意:
console.log打印很有帮助

  

二、v-on鼠标移动事件 —— 时刻显示鼠标地理位置

Vue-小demo、小效果 合集(更新中…)Vue-小demo、小效果 合集(更新中…)

 html:

 <div id="canvas" @mousemove="mouseMove">x: {{mouseX}}, y: {{mouseY}}
<em class="em" @mousemove.stop="">在我的区域内停止更新,都是阻止事件(冒泡)修饰符的功劳</em>
</div>

html Code

css:

 #canvas{
width: 680px;
padding: 150px 0;
text-align: center;
background: #dedede;
}
.em{
display: block;
padding: 10px 5px;
background: #f5c9c9;
font-style: normal;
color: #333;
}

css

Vue.js

 new Vue({
el: "#vue-app",
data: {
mouseX: 0,
mouseY: 0,
},
methods:{
mouseMove: function(event){
console.log("5、我是mouseMove函数");
// console.log(event);
this.mouseX = event.offsetX;
this.mouseY = event.offsetY;
}
}
})

Vue.js

注意:
console.log把event事件输出后,寻找到offsetX和Y属性的

  

声明:

请尊重博客园原创精神,转载或使用图片请注明:

博主:xing.org1^

出处:http://www.cnblogs.com/padding1015/

来源:腾讯课堂 https://ke.qq.com/course/256052#term_id=100301895

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,078
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,553
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,402
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,177
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,814
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898