模板
大纲
- 模板
- Web Components
- 渲染函数
- 强制重新渲染
- 服务端渲染
- 自定义渲染
- 渲染原理
模板
text/x-template
template
<template>
name
delimiters
comments
模板编译
模板转换为渲染函数:
- app.config.compilerOptions
- app.config.compilerOptions.whitespace
- app.config.compilerOptions.delimiters
- app.config.compilerOptions.comments
Vue.compile()
- vue-loader
vue-template-compiler
- vite SFC
@vitejs/plugin-vue
@vitejs/plugin-vue2
Web Components
- app.config.isCustomElement
- Vue.config.ignoredElements
- defineCustomElement()
- customElements.define()
- useShadowRoot()
- useHost()
- $host()
渲染函数
- render()
- h()
- createElement()
- mergeProps()
- resolveComponent()
- resolveDirective()
- withDirectives()
- withModifiers()
- isVNode()
- cloneVNode()
强制重新函数
- $forceUpdate()
$forceUpdate()
可以强制组件实例重新渲染。
信息
考虑到 Vue 的全自动响应式系统,这应该很少需要。唯一可能需要它的情况是当你使用高级响应式 API 显式创建非响应式组件状态时。
JSX
在 Vue 中写 JSX 语法风格的组件需要 babel-plugin-transform-vue-jsx
babel 插件提供转换支持。
- vue-cli
babel-plugin-transform-vue-jsx
- vite
@vitejs/plugin-vue-jsx
@vitejs/plugin-vue2-jsx
服务端函数
- createSSRApp()
- useSSRContext()
- $isServer
- renderToString()
- renderToNodeStream()
- pipeToNodeWritable()
- renderToWebStream()
- pipeToWebWritable()
- renderToSimpleStream()
- https://v2.cn.vuejs.org/v2/guide/ssr.html
- https://v2.ssr.vuejs.org/zh/
自定义函数
- createRenderer()