<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>learn1</title>
</head>
<body> <template id="hello">
<h1>{{msg}} {{user}}</h1>
</template> <template id="form">
<div>
<input :value="value" type="text" id="name" v-on:input="onInput">
</div>
</template> <template id='c'>
<input type="checkbox" v-on:change="onChange"/>
</template> <template id="greetings">
<div>
<my-checkbox v-model='f' value="some value" ></my-checkbox>
<h1>{{f}}</h1>
<hr>
//此处v-model=kk,目的是zz子组件将自己的值传递给父组件的hk
//kk=112,是将父组件的112,或者父组件的其他值传递给子组件
//也就是说在自定义模板上定义v-mode目的是向外传递
//kk=112或其他类似属性,目的是向内传递给自己定义的模板的属性
<zz v-model='hk' kk=""></zz>
</div>
</template> <template id="fff" >
<label>
//这里的:checked是input自带属性,不是我们定义的,它接收checkval方法计算的值
//:kk="kk"对应上面的 zz标签里的 kk=112,可以理解将112传递给kk,kk传递给:kk
//这个 checkval是计算属性,将计算结果传递给:checked,这个checkVal作用是,在父组件里使用子组件,在子组件上的v-model上的值传递给子组件
<input type="radio" :checked="checkVal" :kk="kk" @change="update">
{{ modelVal }}
</label>
</template> <div id="app">
<greetings-component></greetings-component>
</div>
<!-- built files will be auto injected -->
</body>
</html>
 // The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import router from './router'
//import ElementUI from 'element-ui'
//import 'element-ui/lib/theme-chalk/index.css' //import App from './App' Vue.config.productionTip = false
//Vue.use(ElementUI) Vue.component('hello-component', {
template: '#hello',
data: function () {
return {
msg: 'Hello'
}
},
props: ['user']
}); Vue.component('form-component', {
template: '#form',
props: ['value'],
methods: {
onInput: function () {
this.$emit('input', event.target.value)
}
}
}); Vue.component('zz',{
template:'#fff',
model: {
//这里的modlVal ,如果不自己定义,默认是prop:'value',input类似标签
//将值存进value里,我们声明了ModelVal,就不存进value里,而是存进modelVal里
prop: 'modelVal',
event: 'change'
},
props: {
value: {
type: Boolean,
},
modelVal: {
default: ""
},
label: {
type: String
},kk:{
type:String
}
},
computed: {
checkVal() {
console.log("----------")
console.log(this.modelVal)
console.log(this.kk)
console.log("----------")
console.log( this.modelVal === this.value)
return this.modelVal === this.value
}
},
methods: {
update() {
this.$emit('change', this.checkVal)
}}
}) Vue.component('my-checkbox', {
template:'#c',
model: {
//这里就是hello存储true或者false ,替代false
prop: 'hello',
event: 'change'
},
props: {
hello:Boolean, //这里也要先声明hello,
value: String
},
methods:{
onChange () {
console.log(this.hello)
console.log(this.value)
console.log(event.target.checked)
this.$emit('change',event.target.checked) }
}
}) Vue.component('greetings-component', {
template: '#greetings',
data: function () {
return {
user: 'heroaa',
foo:'hello',
f:true,
world:'world',
hk:"",
modelVal:''
}
},
methods:{
get (v) {
console.log(v)
}
}
}); /* eslint-disable no-new */
new Vue({
el: '#app',
data:{
user:'hero'
}
})

很乱,临时保存,自定义v-model的更多相关文章

  1. qsettings 保存自定义结构体(QVariant与自定义结构体相互转化)

    参考博文:QVariant与自定义数据类型转换的方法. 这里摘取其关键内容: 1.将自定义数据类型使用Q_DECLARE_METATYPE宏进行声明,便于编译器识别. 2.在插入对象的时候,声明QVa ...

  2. combox使用自定义的model列表中无元素显示

    自定义的model(stationModel)中有 name 和point两种属性名. 初始化stationModel Combobox{ textRole: 'name' model:station ...

  3. Map集合的遍历方式以及TreeMap集合保存自定义对象实现比较的Comparable和Comparator两种方式

    Map集合的特点 1.Map集合中保存的都是键值对,键和值是一一对应的 2.一个映射不能包含重复的值 3.每个键最多只能映射到一个值上 Map接口和Collection接口的不同 Map是双列集合的根 ...

  4. keras中保存自定义层和loss

    在keras中保存模型有几种方式: (1):使用callbacks,可以保存训练中任意的模型,或选择最好的模型 logdir = './callbacks' if not os.path.exists ...

  5. log4net:保存自定义参数到数据库

    log4net:保存日志到数据库 自定义参数 新建一个类,继承于PatternLayoutConverter public class CustomerPatternConverter : Patte ...

  6. iOS 使用NSUserdefault 保存自定义的 对象

    一:NSUserDefaults支持的数据格式有:NSNumber(Integer.Float.Double),NSString,NSData,NSArray,NSDictionary,BOOL类型: ...

  7. OC中保存自定义类型对象的持久化方法

    OC中如果要将自定义类型的对象保存到文件中,必须进行以下三个条件: 想要把存放自定义类型的数组进行 持久化(就是将内存中的临时数据以文件<数据库等>的形式写到磁盘上)必须满足: 1. 自定 ...

  8. docker基本概念,创建、起动实例,保存自定义镜像等常用操作

    14年docker火了一阵,当时自学整理了一份文档,后来冷落了. 现在发现很多同事还是想学习docker,但无从下手,所以重新整理了这篇分享,10分钟就可以带你彻底理解docker,并能够创建属于自己 ...

  9. Git的Bug分支----临时保存现场git stash

    软件开发中,bug就像家常便饭一样,有了bug就需要修复,在Git中,由于分支是如此的强大,所以每个bug通过一个新的分支来修复,在修复后,合并分支,然后将临时分支删除. 当你接到一个修复代号为119 ...

随机推荐

  1. ORACLE EBS中查看系统已经打过的补丁

    SELECT COUNT (BUG_NUMBER)  FROM AD_BUGS WHERE BUG_NUMBER LIKE '%7303031%'  --对应 patch号 ; --TABLESAD_ ...

  2. 为已经存在的TFS团队项目配置SharePoint集成

    配置好TFS团队项目集合与SharePoint站点集的集成后,就可以在新建TFS团队项目时集成SharePoint站点,也可以为已经存在的团队项目配置SharePoint站点的集成,如下图:   Fi ...

  3. pssh执行本地文件(脚本)

    场景:目标命令中含有特殊符号,导致pssh批量执行可能出问题. 用法: pssh -h RemoteHosts.ip -P -I < ~/LocalScript.sh

  4. 安装、启动consul

    1.下载 从consul官网https://www.consul.io/downloads.html下载 2.解压.配置 将下载的  consul_1.4.4_linux_amd64.zip 解压 t ...

  5. Devexpress WPF教程

    [视频专辑]酷炫界面开发神器DevExpress WPF视频教程(36集全) http://www.devexpresscn.com/post/620.html

  6. Could not find any resources for the specified culture or the neutral culture

    问题解决办法是: 打开资源文件,将access modifier:下拉项设置为“internal”即可

  7. javascript学习日记1

    1.JavaScript:写入 HTML 输出 document.write("<h1>This is a heading</h1>"); document ...

  8. 【OCP-12c】2019年CUUG OCP 071考试题库(75题)

    75.Which statements are correct regarding indexes? (Choose all that apply.) A. A non-deferrable PRIM ...

  9. “全栈2019”Java多线程第六章:中断线程interrupt()方法详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  10. IIS7的网站通过https访问提示ssl_error_rx_record_too_long

    IIS7的网站通过https访问,提示ssl_error_rx_record_too_long,如下图所示: 解决办法: 一.导入服务器的SSL证书至IIS 1.打开IIS,找到服务器证书 2.导入本 ...