var vm = new Vue({
// options
})
var vm = new Vue({
el: '#example',
data: {
a: 1
},
computed: {
// a computed getter
b: function () {
// `this` points to the vm instance
return this.a + 1
}
}
})
var Profile = Vue.extend({
template: "<div> Lily </div>"
});
<div id="todo"> <my-profile></my-profile> <form v-on:submit="add" v-on:submit.prevent> <input type="text" v-model="input"/> <input type="submit" value='add' /> </form> ... </div>
var vm = new Vue({
el: "#todo",
components: {
"my-profile": Profile
},
...
}
var MyComponent = Vue.extend({
data: function () {
return { a: 1 }
}
})
<table> <tr is="my-component"></tr> </table>
var Profile = Vue.extend({
props: ["name"],
template: `
<h2>{{name}}'s Todo List</h2>
<h4>{{name}} is a good girl</h4>
`
});
<!-- default, one-way-down binding --> <child :msg="parentMsg"></child> <!-- explicit two-way binding --> <child :msg.sync="parentMsg"></child> <!-- explicit one-time binding --> <child :msg.once="parentMsg"></child>
var Profile = Vue.extend({
input: {
type: String
}
});
var Form = Vue.extend({
props: {
username: {
type: String,
default: "Unnamed"
}
},
data: function() {
return {
input: "",
};
},
template: `
<h1>{{username}}'s Todo List</h1>
<form v-on:submit="add" v-on:submit.prevent>
<input type="text" v-model="input"/>
<input type="submit" value='add' />
</form>
`,
methods: {
add: function() {
this.$dispatch("add", this.input); //这里就是向父组件发送消息
this.input = "";
}
}
});
var List = Vue.extend({
template: `
<ul>
<li v-for='todo in list'>
<label v-bind:class="{ done : todo.done }" >
<input type="checkbox" v-model="todo.done"/>
{{todo.title}}
</label>
</li>
</ul>`,
props: {
initList: {
type: Array
}
},
data: function() {
return {
list: []
}
},
events: {
add: function(input) {
if(!input) return false;
this.list.unshift({
title: input,
done: false
});
}
}
});
var vm = new Vue({
el: "#todo",
components: {
"todo-form": Form,
"todo-list": List
},
events: {
add: function(input) {
this.$broadcast("add", input);
}
}
});
<div id="todo"> <todo-form username='Lily'></todo-form> <todo-list></todo-list> </div>
var Todo = Vue.extend({
template: `
<div id="todo">
<todo-form username='Lily'></todo-form>
<todo-list></todo-list>
<slot>not show</slot>
</div>
`,
components: {
"todo-form": Form,
"todo-list": List
},
events: {
add: function(input) {
this.$broadcast("add", input);
}
}
});
var About = Vue.extend({
template: `
<div id="about">
<p>About Todo List V0.1.0</p>
<p>Content here</p>
</div>`
});
var vm = new Vue({
el: "body",
data: {
currentView: "todo"
},
components: {
"todo": Todo,
"about": About
}
});
<component :is="currentView"></component> <ul> <li><label><input type="radio" name='page' value='todo' v-model='currentView'> Home</label></li> <li><label><input type="radio" name='page' value='about' v-model='currentView'> About</label></li> </ul>
vm.msg = 'new message' // change data
vm.$el.textContent === 'new message' // false
Vue.nextTick(function () {
vm.$el.textContent === 'new message' // true
})
vm.$nextTick(function () {
this.$el.textContent === 'new message' // true
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有