v-html渲染組件問(wèn)題
由于前面對(duì)html進(jìn)行過(guò)解析,今天想用vue拖拽,實(shí)現(xiàn)一手類(lèi)似快站那種自動(dòng)生成代碼,結(jié)果就遇到了拖拽組件過(guò)去怎么無(wú)法解析的問(wèn)題,因?yàn)関ue的v-html為了防止xss攻擊只能解析html
思路
先實(shí)現(xiàn)簡(jiǎn)單頁(yè)面 分三塊左中右,左邊是需要拖動(dòng)的組件,中間是用于組件排列顯示,右邊是解析出的代碼
左邊組件列表代碼
<div ref="test" > <one-component :title="title[0]" element="<el-radio v-model='radio' label='1'>備選項(xiàng)</el-radio>"> <el-radio slot="component" v-model="radio" label="1">備選項(xiàng)</el-radio> </one-component> </div> </template> <script> import OneComponent from '../components/oneComponent' export default { name: '', data() { return { radio: '2', title: ['Radio 單選框'] } }, components:{ OneComponent }, } </script> <style lang="stylus" scoped> </style>
中間組件顯示代碼
<div class="all"> <el-form label-width="80px" label-position="left" :model="ruleForm" :rules="rules"> <el-form-item label="模擬寬" prop="inputW"> <el-input v-model="ruleForm.inputW" placeholder="請(qǐng)輸入寬"></el-input> </el-form-item> <el-form-item label="模擬高" prop="inputH"> <el-input v-model="ruleForm.inputH" placeholder="請(qǐng)輸入高"></el-input> </el-form-item> </el-form> <Variablebox class="box" :width="ruleForm.inputW" :height="ruleForm.inputH" ></Variablebox> </div> </template> <script> import Variablebox from "../components/Variablebox"; export default { name: "", data() { var checkSize = (rule, value, callback) => { console.log(value); if (value < 500 || value > 1000) { callback(new Error("建議500 ~ 1000內(nèi)的數(shù)字")); } else if (!Number.isInteger(Number(value))) { callback(new Error("請(qǐng)輸入數(shù)字值")); } else { callback(); } }; return { ruleForm: { inputW: 500, inputH: 500 }, rules: { inputW: [{ validator: checkSize, trigger: "blur" }], inputH: [{ validator: checkSize, trigger: "blur" }] } }; }, methods: { }, components: { Variablebox } }; </script> <style lang="stylus" scoped> .all padding: 0 20px display: flex flex-direction: column </style>
接下來(lái)實(shí)現(xiàn)組件的拖拽使用drag和drop 將組件顯示在Variablebox頁(yè)面上,使用v-html無(wú)效后,百度了一下,發(fā)現(xiàn)基本上叫使用vue.Vue.compile( template ) 和render但是沒(méi)給例子
compile是將一個(gè)模板字符串編譯成 render 函數(shù),就是最后
都是render調(diào)用createElement,轉(zhuǎn)化成html,但是我們我們是直接渲染
</el-radio slot="component" v-model="radio" label="1"/>
所以個(gè)人
感覺(jué)行不通,最后只能?chē)L試新建組件然后掛載上去
new Vue({ // el: ‘#app' template: this.ele, data:{ radio: '2' }, }).$mount("#apps");
這樣算是暫時(shí)決解掉這個(gè)問(wèn)題吧
vue中運(yùn)用v-html渲染標(biāo)簽
獲取后臺(tái)數(shù)據(jù)帶 標(biāo)簽 內(nèi)容,需要渲染到頁(yè)面展示。最終效果如下:圖文排版
1.首先拿到數(shù)據(jù),單獨(dú)處理
2.接著在html中輸出即可
相關(guān)文章
Vuex中this.$store.commit()和this.$store.dispatch()區(qū)別說(shuō)明
這篇文章主要介紹了Vuex中this.$store.commit()和this.$store.dispatch()區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04Vue實(shí)現(xiàn)數(shù)據(jù)篩選與搜索功能的示例代碼
在許多Web應(yīng)用程序中,數(shù)據(jù)篩選和搜索是關(guān)鍵的用戶(hù)體驗(yàn)功能,本文將深入探討在Vue中如何進(jìn)行數(shù)據(jù)篩選與搜索的實(shí)現(xiàn),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-10-10useEffect理解React、Vue設(shè)計(jì)理念的不同
這篇文章主要為大家介紹了useEffect理解React、Vue設(shè)計(jì)理念的不同詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09el-form-item中表單項(xiàng)label和表單項(xiàng)內(nèi)容換行實(shí)現(xiàn)方法
這篇文章主要給大家介紹了el-form-item中表單項(xiàng)label和表單項(xiàng)內(nèi)容換行實(shí)現(xiàn)的相關(guān)資料,每個(gè)表單el-form由多個(gè)表單域el-form-item組成,需要的朋友可以參考下2023-09-09關(guān)于vue-cli 3配置打包優(yōu)化要點(diǎn)(推薦)
這篇文章主要介紹了vue-cli 3配置打包優(yōu)化要點(diǎn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04解決vue打包報(bào)錯(cuò)Unexpected token: punc的問(wèn)題
這篇文章主要介紹了解決vue打包報(bào)錯(cuò)Unexpected token: punc的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10Vue-Cli如何在index.html中進(jìn)行環(huán)境判斷
這篇文章主要介紹了Vue-Cli如何在index.html中進(jìn)行環(huán)境判斷問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03使用el-form-item設(shè)置標(biāo)簽長(zhǎng)度
這篇文章主要介紹了使用el-form-item設(shè)置標(biāo)簽長(zhǎng)度方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10