Appearance
动态编译 Vue.compile(str)
完整版情况可以将模板加载成render函数,实现远程加载功能
阉割版的响应数据 Vue.observable(obj)
创建一个可响应对象,目前我们的可以响应对象在data,watch,computed 中, 这个阉割版的可以响应对象用于渲染函数和计算属性中
watch可以监听一个数组,也可以是一个方法
js
watch: {
a: 'someMethod' // vm实例中方法,
b: [
{
handler: function () {},
deep: true,
immediate: true
},
function () {},
'someMethod'
]
}插槽新功能 v-slot
- v-slot:slotName 指定具名插槽
- v-slot在单个插槽的情况下可以绑定非template*,其余必*须绑定到组件上
- v-slot可以简写为#, 认插槽需要#default
v-bind 支持对象绑定, 动态绑定
html
<!-- 绑定一个 attribute -->
<img v-bind:src="imageSrc">
<!-- 动态 attribute 名 (2.6.0+) -->
<button v-bind:[key]="value"></button>
<!-- 缩写 -->
<img :src="imageSrc">
<!-- 动态 attribute 名缩写 (2.6.0+) -->
<button :[key]="value"></button>
<!-- 内联字符串拼接 -->
<img :src="'/path/to/images/' + fileName">
<!-- class 绑定 -->
<div :class="{ red: isRed }"></div>
<div :class="[classA, classB]"></div>
<div :class="[classA, { classB: isB, classC: isC }]">
<!-- style 绑定 -->
<div :style="{ fontSize: size + 'px' }"></div>
<div :style="[styleObjectA, styleObjectB]"></div>
<!-- 绑定一个全是 attribute 的对象 -->
<div v-bind="{ id: someProp, 'other-attr': otherProp }"></div>
<!-- 通过 prop 修饰符绑定 DOM attribute -->
<div v-bind:text-content.prop="text"></div>
<!-- prop 绑定。“prop”必须在 my-component 中声明。-->
<my-component :prop="someThing"></my-component>
<!-- 通过 $props 将父组件的 props 一起传给子组件 -->
<child-component v-bind="$props"></child-component>
<!-- XLink -->
<svg><a :xlink:special="foo"></a></svg>v-pre 手动指定这个元素和其子元素不需要编译。直接展示原始标签
不需要响应式的数据记得冻结,比如表格数据
vue
<script>
export default {
data() {
retur: {
data: []
}
},
async beforeMounted() {
this.data = await this.getData()
},
methods: {
async getData() {
return Object.freeze(someData)
}
}
}
</script>静态内容尽量使用template模板渲染, 不使用jsx或者render函数。提高性能
complie 会优化render 函数,直接写没有优化过程。
