v-html渲染組件問題
由于前面對html進行過解析,今天想用vue拖拽,實現(xiàn)一手類似快站那種自動生成代碼,結果就遇到了拖拽組件過去怎么無法解析的問題,因為vue的v-html為了防止xss攻擊只能解析html
思路
先實現(xiàn)簡單頁面 分三塊左中右,左邊是需要拖動的組件,中間是用于組件排列顯示,右邊是解析出的代碼
左邊組件列表代碼
<div ref="test" > <one-component :title="title[0]" element="<el-radio v-model='radio' label='1'>備選項</el-radio>"> <el-radio slot="component" v-model="radio" label="1">備選項</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="請輸入寬"></el-input> </el-form-item> <el-form-item label="模擬高" prop="inputH"> <el-input v-model="ruleForm.inputH" placeholder="請輸入高"></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("請輸入數(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>
接下來實現(xiàn)組件的拖拽使用drag和drop 將組件顯示在Variablebox頁面上,使用v-html無效后,百度了一下,發(fā)現(xiàn)基本上叫使用vue.Vue.compile( template ) 和render但是沒給例子
compile是將一個模板字符串編譯成 render 函數(shù),就是最后
都是render調(diào)用createElement,轉(zhuǎn)化成html,但是我們我們是直接渲染
</el-radio slot="component" v-model="radio" label="1"/>
所以個人
感覺行不通,最后只能嘗試新建組件然后掛載上去
new Vue({ // el: ‘#app' template: this.ele, data:{ radio: '2' }, }).$mount("#apps");
這樣算是暫時決解掉這個問題吧
vue中運用v-html渲染標簽
獲取后臺數(shù)據(jù)帶 標簽 內(nèi)容,需要渲染到頁面展示。最終效果如下:圖文排版
1.首先拿到數(shù)據(jù),單獨處理
2.接著在html中輸出即可
相關文章
Vuex中this.$store.commit()和this.$store.dispatch()區(qū)別說明
這篇文章主要介紹了Vuex中this.$store.commit()和this.$store.dispatch()區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04Vue實現(xiàn)數(shù)據(jù)篩選與搜索功能的示例代碼
在許多Web應用程序中,數(shù)據(jù)篩選和搜索是關鍵的用戶體驗功能,本文將深入探討在Vue中如何進行數(shù)據(jù)篩選與搜索的實現(xiàn),感興趣的小伙伴可以跟隨小編一起學習一下2023-10-10el-form-item中表單項label和表單項內(nèi)容換行實現(xiàn)方法
這篇文章主要給大家介紹了el-form-item中表單項label和表單項內(nèi)容換行實現(xiàn)的相關資料,每個表單el-form由多個表單域el-form-item組成,需要的朋友可以參考下2023-09-09解決vue打包報錯Unexpected token: punc的問題
這篇文章主要介紹了解決vue打包報錯Unexpected token: punc的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10Vue-Cli如何在index.html中進行環(huán)境判斷
這篇文章主要介紹了Vue-Cli如何在index.html中進行環(huán)境判斷問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03