Vue - fragment knowledge
Basic
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<span v-bind:title="message">
<p v-if="seen">现在你看到我了</p>
<li v-for="todo in todos">
</li>
<button v-on:click="reverseMessage">逆转消息</button>
<input v-model="message">
<form v-on:submit.prevent="onSubmit">...</form>
Attentions
var vm = new Vue({
data: data
})
Object.freeze(obj)
vm.a === data.a
var data = { a: 1 }
var vm = new Vue({
el: '#example',
data: data
})
vm.$data === data
vm.$el === document.getElementById('example')
vm.$watch('a', function (newValue, oldValue) {
})
New Features
<span v-once>这个将不会改变: </span>
<div v-bind:id="'list-' + id"></div>
<p>Using v-html directive: <span v-html="rawHtml"></span></p>
<a v-bind:href="url">...</a>
<a :href="url">...</a>
<a v-on:click="doSomething">...</a>
<a @click="doSomething">...</a>
<div class="static"
v-bind:class="{ active: isActive, 'text-danger': hasError }">
</div>
<div v-bind:class="[activeClass, errorClass]"></div>
<div v-bind:class="[isActive ? activeClass : '', errorClass]"></div>
<div v-bind:class="[{ active: isActive }, errorClass]"></div>
<div v-bind:style="[baseStyles, overridingStyles]"></div>
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
<div :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }"></div>
<div v-bind:style="styleObject"></div>
data: {
styleObject: {
color: 'red',
fontSize: '13px'
}
}
Mustache 语法不能作用在 HTML 特性上,遇到这种情况应该使用 v-bind 指令: