<!DOCTYPE html>
<html> <head>
<meta charset="utf-8" />
<title></title>
<style>
.active {
color: red;
} .text-success {
color: #009966;
font-size: 20px;
} .fontWeight {
font-weight: bold;
}
</style>
</head> <body>
<div id="list">
<ul>
<div v-bind:class="[fontWeight,textSuccess]">欢迎品尝</div>
<input type="text" v-model="moonstuffing" maxlength="5" placeholder="请输入您喜欢的月饼馅" />
<div v-bind:class="classObject">中秋节月饼馅</div>
<li v-for="item in mooncake">{{item}}</li> </ul>
<div v-bind:style="obj">花好月圆夜</div>
<my-component v-bind:class="textSuccess" v-bind:message="txt"></my-component>
<!--自定义UI组件--> <user-input v-if="ok" :message="user.loginType" :changevalue="changevaluefn" :values="username" :types="user.textType" :placeholdertext="user.placeText" key="username"></user-input>
<user-input v-else :message="user.loginType" :changevalue="changevaluefn" :values="useremail" :types="user.textType" :placeholdertext="user.placeText" key="useremail"></user-input> <button @click="change">点击切换</button> <hr /> <!--<template> 元素当做包装元素-->
<template v-if="qiehuan">
<label>Username</label>
<input placeholder="Enter your username" key="username-input">
</template> <template v-else>
<label>Email</label>
<input placeholder="Enter your email address" key="email-input">
</template> <button @click="tab">点击切换(使用包装元素)</button> <hr /> <div v-show="ok">
哈哈我显示了
</div> <!-- v-for v-if 结合使用-->
<h1> v-for v-if 结合使用</h1>
<ul>
<li v-for = "item in money" v-if="item.price <= 40">{{item.txt}}</li> </ul> </div>
</body>
<script src="js/vue.js"></script> <script type="text/javascript">
Vue.component('user-input', {
template: '<div><label>{{message}}</label><input :value="values" @input="changevalue" @onpropertychange="changevalue" :type="types" :placeholder="placeholdertext"></div>',
props: ["message", "types", "placeholdertext","values","changevalue"], }) Vue.component('my-component', {
template: '<p class="foo bar">{{message}}</p>',
props: ["message"]
}) var moon = new Vue({
el: "#list",
data: {
ok:true,
qiehuan:true,
isActive: true,
isSuccess: true,
moonstuffing: '',
mooncake: ["蛋黄", "五仁", "豆沙", "莲蓉"],
fontWeight: "fontWeight",
textSuccess: "text-success",
txt: "哈哈",
activeColor: "red",
fontSize: 60,
obj: {
color: "red",
fontSize: "60px"
},
user: {
loginType: "username",
textType: "email",
placeText: "请输入用户名"
},
username:'用户名',
useremail:'邮箱',
money:[
{price: 10,txt:"10元"},
{price: 20,txt:"20元"},
{price: 30,txt:"30元"},
{price: 40,txt:"40元"},
{price: 50,txt:"50元"},
{price: 60,txt:"60元"},
{price: 70,txt:"70元"},
{price: 80,txt:"80元"}
] },
methods: { change: function() {//点击按钮切换 if(this.ok) {
this.ok = false;//控制组件显示隐藏 this.user = {
loginType: "email",
textType: "email",
placeText: "请输入邮箱"
} } else { this.ok = true;//控制组件显示隐藏 this.user = {
loginType: "username",
textType: "text",
placeText: "请输入用户名"
} } },
changevaluefn:function(e){//监听值变化
var e = e || window.event;
var target = e.target || e.srcElement; if(this.ok) {
this.username = target.value //接收用户名
} else {
this.useremail = target.value//接收邮箱 }
},
tab:function() {//点击按钮切换 if(this.qiehuan) {
this.qiehuan = false; } else { this.qiehuan = true;//控制组件显示隐藏 } }
},
watch: { //监听数据发送改变
moonstuffing: function(newValue, oldValue) { //监听属性
console.log(oldValue)
if(newValue != '') {
moon.mooncake.push(newValue)
moon.isActive = true;
} else {
moon.isActive = false;
}
}
}, computed: {
classObject: function() {
return {
active: this.isActive,
'text-success': this.isSuccess
}
}
}
})
</script> </html>

最新文章

  1. Visual Studio2008环境下查找C#中方法的“查看所有引用”
  2. jQuery选择器引擎和Sizzle介绍
  3. C#中的using和yield return混合使用
  4. HT For Web 拓扑图背景设置
  5. go-- 用go-mssql驱动连接sqlserver数据库
  6. MVC公开课 &ndash; 1.基础 (2013-3-15广州传智MVC公开课)
  7. MySQL优化技巧之三(索引操作和查询优化)
  8. Egret应用开发实践(01) Egret与WebPack
  9. 手把手教你清除WIN7的C盘垃圾
  10. html 5 本地数据库(Web Sql Database)核心方法openDatabase、transaction、executeSql 详解
  11. EntityManager 实例化方法
  12. Linux下C/C++和lua交互-Table
  13. 【Unity Shaders】使用CgInclude让你的Shader模块化——使用#define指令创建Shader
  14. 字符串匹配KMP算法的讲解C++
  15. Eclipse的配置
  16. C语言:传值,传地址
  17. ubuntu下zaibbix3.2报警搭建
  18. LeetCode 26 Remove Duplicates from Sorted Array (移除有序数组中重复数字)
  19. n=n+1 放在print(s)的前/后的影响
  20. C++中函数模版与类模版

热门文章

  1. git clone 带用户名密码的形式但包含@等特殊符号无法正常解析
  2. gbdt的面试要点总结-上篇
  3. AngularJS学习篇(二十一)
  4. URLs对象 blob URL
  5. 基于webpack搭建的vue+element-ui框架
  6. java模拟登陆功能
  7. java的linux命令
  8. linux终端自定义命令的别名
  9. Builder模式的思考(Effective Java)
  10. iOS项目的命名规范