你需要知道的vue2 jsx render函数
生活随笔
收集整理的這篇文章主要介紹了
你需要知道的vue2 jsx render函数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
通常開發(fā)vue我們使用的是模板語法,其實還有和react相同的語法,那就是render函數(shù),同樣支持jsx語法。
Vue 的模板實際是編譯成了 render 函數(shù)。
?
0 傳統(tǒng)的createElement方法
createElement('anchored-heading', {props: {level: 1}}, [createElement('span', 'Hello'),' world!'] )
渲染成下面這樣 <anchored-heading :level="1"> <span>Hello</span> world! </anchored-heading> ?
?
?
?
1 使用jsx語法
?
安裝下面的東東
這就是會有一個 Babel plugin 插件,用于在 Vue 中使用 JSX 語法的原因,它可以讓我們回到于更接近模板的語法上。
https://github.com/vuejs/babel-plugin-transform-vue-jsx
?
npm install\babel-plugin-syntax-jsx\babel-plugin-transform-vue-jsx\babel-helper-vue-jsx-merge-props\babel-preset-es2015\--save-dev然后編輯.babelrc文件
{
"presets": ["es2015"],
"plugins": ["transform-vue-jsx"]
}
?
必須要像這樣寫
Vue.component('jsx-example', {render (h) { // <-- h must be in scopereturn <div id="foo">bar</div>} })?
轉(zhuǎn)載于:https://www.cnblogs.com/bhaltair/p/6648946.html
總結(jié)
以上是生活随笔為你收集整理的你需要知道的vue2 jsx render函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做梦梦到狼是什么意思
- 下一篇: Laravel Session 遇到的坑