<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<!-- 数据渲染 -->
<div id="app">
<!-- 模板语法 -->
<div>
<span>{{ message }}</span>
<span v-once>这个将不会改变: {{ message }}</span>
<!-- 输出真正的 HTML -->
<span v-html="message"></span>
<!-- 属性绑定 双大括号不能在 HTML attributes 中使用 -->
<!-- <div v-bind:id="dynamicId"></div> -->
</div>
<!-- 条件渲染 -->
<div>
<h1 v-if="flag">Vue is awesome!</h1>
<h1 v-else>false</h1>
<!-- <template> 元素当做不可见的包裹元素 -->
<template v-if="flag">
<h1>Title</h1>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
</template>
<div v-if="type === 'A' ">
Now you see me
</div>
<div v-else-if="type === 'B' ">
Now you don't
</div>
<div v-else>
Not A/B/C
</div>
</div>
<!-- 列表渲染 -->
<div>
<div v-for="(item, index) in array" v-bind:key='item.id' >
{{index}} + {{item.message}} + {{item.name}}
</div>
<div v-for="(value, name) in object">
{{name}} + {{value}}
</div>
</div>
<!-- 事件处理 -->
<div>
<!-- v-on 指令监听 DOM 事件 -->
<div>
<button v-on:click="fun">Add 1</button>
<p>The button above has been clicked {{ counter }} times.</p>
</div>
</div>
<!-- 双向绑定 -->
<div>
<!-- v-model 指令在表单 <input>、<textarea> 及 <select> 元素上创建双向数据绑定。 -->
<input v-model="message">
<p>Message is: {{ message }}</p>
<!-- 多选框 绑定的是value -->
<input type="checkbox" id="jack" value="Jack" v-model="checkedNames">
<label for="jack">Jack</label>
<input type="checkbox" id="john" value="John" v-model="checkedNames">
<label for="john">John</label>
<br>
<span>Checked names: {{ checkedNames }}</span>
<!-- selected -->
<select v-model="selected">
<option disabled value="">请选择</option>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<span>Selected: {{ selected }}</span>
</div>
</div>
</body>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
<script>
//创建vue实例 ,viewModel层
var app = new Vue({
//挂载元素
el : "#app",
data : {
message : "vue",
flag : true,
type : 'A',
array: [
{ id: 1, message: 'Foo' , name : 'L' },
{ id: 2, message: 'Bar' , name : 'M'}
],
object : {
title: 'How to do lists in Vue',
author: 'Jane Doe',
},
counter : 0,
checkedNames: [],
selected: ""
},
methods : {
fun: function(e){
console.log(e)
console.log(this);
this.counter = this.counter + 1;
}
},
//生命周期函数 实例创建之后
created : function (){
//this app实例
this.message = "str"
}
})
</script>
</html>
标签:Vue,name,--,app,counter,基础,语法,message
From: https://www.cnblogs.com/lwx11111/p/16942387.html