Vue 框架-08-基础实战 demo

Vue 框架-08-基础实战 demo

前面介绍了有 7 篇了,都是小实例,没有相对完整的应用,虽然有些功能挺实用,但还是有的不常用的,今天记录一篇关于前几篇基础内容的实战 demo,也是对 Vue 基础的简单应用。

来看截图:

在这里插入图片描述

源代码 html 文件:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>VueLearn-cnblogs/xpwi</title>
		<!--引入自定义的样式-->
		<link rel="stylesheet" href="css/demo.css" />
		<!--引入 vue 核心 js-->
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
		
	</head>
	<body>
		
		<!--vue-app 是根容器,定义一个 id,然后在 js 里操作-->
		<div id="vue-app">
			
			<h2> Vue 基础 demo </h2>
			<hr />
			
		
			<button v-on:click="selectA=true;selectB=false;selectedB=false;selectedA=true" v-bind:class="{red:selectedA}">爱心打气筒</button>
			<button v-on:click="selectA=false;selectB=true;selectedB=true;selectedA=false" v-bind:class="{red:selectedB}">选择B</button>
			
			<div class="main1" v-if="selectA" v-bind:class="{change:boom}">
				
				<h3 id="title1">爱心打气筒</h3>
			
			<div id="process">
				<div id="inProcess" v-bind:style="{width:proLength +'%'}">></div>
			
			</div>
			
			<button @click="add()" v-show="!ended">打气</button>
			<button @click="restart()" >重置</button>
			</div>
			<div class="main2" v-else-if="selectB">这里什么都没有</div>
			
			
			
			<hr />
			<h3>功能:</h3>
			<ul>
				<li v-for="i in tips">{{i}}</li>
			</ul>
			
			
			
			
			
		</div>
		
		<!--引入自己的 js,注意必须写在 body 标签里最后,因为必须先加载你的整个 HTML DOM,才回去执行 vue 实例-->
		<script type="text/javascript" src="js/demo.js" ></script>
	</body>
</html>

源代码 js 文件:

//实例化 vue 对象
new Vue({
	//注意代码格式
	
	//el:element 需要获取的元素,一定是 html 中的根容器元素
	el:"#vue-app",
	data:{
		selectA : true,
		selectB : false,
		selectedA : true,
		selectedB : false,
		ended : false,
		boom : false,
		len : 0,
		proLength : 0,
		//下面数组的元素是 json 对象,用于前台 for遍历
		tips:["1.选项卡切换","2.数据遍历","3.条件语句","4.动态css"],

	},
	methods:{
		add:function() {
			this.proLength += 25;
			if (this.proLength == 100){
				this.boom = true;
				this.ended = !this.ended;
			}
		},
		restart:function(){
			this.proLength = 0;
			this.boom = false;
			this.ended = false;
		}
		
	
	}

});

源代码 css 文件:

.red{
	color: red;
}

.main1{
	height:300px;
	width: 400px;
	background: url(../img/1.jpg) no-repeat;
}

.change{
	height:300px;
	width: 400px;
	background: url(../img/2.jpg) no-repeat;
}

.main2{
	height:300px;
	width: 400px;
	background: url(../img/03.jpg) no-repeat;
}

#process{
	margin-top: 10px;
	background-color: #ffffff;
	width: 100px;
}

#inProcess{
	margin-top: 10px;
	background-color: #ff0000;
}
#title1{
	color: #ffffff;margin: 0;
}

更多文章:

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肖朋伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值