Files
bea-mid/console-web/demo/demo01.html
T
2019-08-26 07:25:43 +08:00

173 lines
5.0 KiB
HTML

<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
{{ message }}
</div>
<div id="app-2">
<span v-bind:title="message">
鼠标悬停几秒钟查看此处动态绑定的提示信息!
</span>
</div>
<div id="app-3">
<p v-if="seen">现在你看到我了</p>
</div>
<div id="app-4">
<ol>
<li v-for="todo in todos">
{{ todo.text }}
</li>
</ol>
</div>
<div id="app-5">
<p>{{ message }}</p>
<button v-on:click="reverseMessage">逆转消息</button>
</div>
<div id="app-6">
<p>{{ message }}</p>
<input v-model="message" />
<todo-item v-for="item in groceryList" v-bind:todo1="item" v-bind:key="item.id"></todo-item>
<button @click="countered">Add 1</button>
<p>The button above has been clicked {{ counter }} times.</p>
<button v-on:click="say('hi')">Say hi</button>
<button v-on:click="say('what')">Say what</button>
<button-counter></button-counter>
<button-counter></button-counter>
<div id="blog-posts-events-demo">
<div :style="{ fontSize: postFontSize + 'em' }" v-on:enlarge-text="postFontSize1 += $event">
<blog-post v-for="post in posts" v-bind:key="'blog-post-' + post.id" v-bind:post="post">
Something bad happened.
</blog-post>
</div>
</div>
<custom-input v-model="searchText"></custom-input>
<label>{{searchText}}</label>
</div>
<ol></ol>
<script>
Vue.component("todo-item", {
props: ["todo1"],
template: "<li>{{ todo1.text }}</li>"
});
Vue.component("button-counter", {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
});
Vue.component('blog-post', {
props: ['post'],
template: `
<div>
<h3>{{ post.title }}</h3>
<button v-on:click="$emit('enlarge-text', 0.1)">
Enlarge text
</button>
<slot></slot>
<div v-html="post.content"></div>
</div>
`
});
Vue.component('custom-input', {
props: ['value'],
template: `
<input
v-bind:value="value"
v-on:input="$emit('input', $event.target.value)"
>
`
})
var app = new Vue({
el: "#app",
data: {
message: "Hello Vue!"
}
});
var app2 = new Vue({
el: "#app-2",
data: {
message: "页面加载于 " + new Date().toLocaleString()
}
});
var app3 = new Vue({
el: "#app-3",
data: {
seen: true
}
});
var app4 = new Vue({
el: "#app-4",
data: {
todos: [
{ text: "学习 JavaScript" },
{ text: "学习 Vue" },
{ text: "整个牛项目" }
]
}
});
var app5 = new Vue({
el: "#app-5",
data: {
message: "Hello Vue.js!"
},
methods: {
reverseMessage: function () {
this.message = this.message
.split("")
.reverse()
.join("");
}
}
});
var app6 = new Vue({
el: "#app-6",
data: {
message: "hello vue",
groceryList: [
{ id: 0, text: "蔬菜" },
{ id: 1, text: "奶酪" },
{ id: 2, text: "随便其它什么人吃的东西" }
],
counter: 0,
title: 'xxx',
posts: [
{ id: 1, title: 'My journey with Vue', content: 'My journey with Vue' },
{ id: 2, title: 'Blogging with Vue', content: 'My journey with Vue' },
{ id: 3, title: 'Why Vue is so fun', content: 'My journey with Vue' }
],
postFontSize: 1,
searchText: ''
},
created: function () {
console.log("app-6 created");
},
mounted: function () {
console.log("app-6 mounted");
},
updated: function () {
console.log("app-6 updated");
},
methods: {
countered: function (event) {
this.counter++;
},
say: function (message) {
alert(message)
}
}
});
</script>
</body>
</html>