Since I have parsed HTML before, I want to use Vue drag and drop today to achieve automatic code generation similar to that of Kuai Station. As a result, I encountered the problem that the drag component could not be parsed in the past, because Vue's v-html can only parse HTML to prevent XSS attacks. IdeasFirst, implement a simple page divided into three parts: left, middle, and right. The left side is the component that needs to be dragged, the middle is used for component arrangement and display, and the right side is the parsed code Component list code on the left <div ref="test" > <one-component :title="title[0]" element="<el-radio v-model='radio' label='1'>Alternative options</el-radio>"> <el-radio slot="component" v-model="radio" label="1">Options</el-radio> </one-component> </div> </template> <script> import OneComponent from '../components/oneComponent' export default { name: '', data() { return { radio: '2', title: ['Radio single checkbox'] } }, components:{ OneComponent }, } </script> <style lang="stylus" scoped> </style> Intermediate component display code <div class="all"> <el-form label-width="80px" label-position="left" :model="ruleForm" :rules="rules"> <el-form-item label="simulated width" prop="inputW"> <el-input v-model="ruleForm.inputW" placeholder="Please enter width"></el-input> </el-form-item> <el-form-item label="Simulation height" prop="inputH"> <el-input v-model="ruleForm.inputH" placeholder="Please enter height"></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("A number between 500 and 1000 is recommended")); } else if (!Number.isInteger(Number(value))) { callback(new Error("Please enter a numeric value")); } 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> Next, we implement the dragging of components using drag and drop to display the components on the Variablebox page. After using v-html failed, I searched on Baidu and found that it basically called using vue.Vue.compile( template ) and render, but there was no example. compile compiles a template string into a render function, which means that render calls createElement in the end and converts it into HTML, but we render directly new Vue({ // el: '#app' template: this.ele, data:{ radio: '2' }, }).$mount("#apps"); This will temporarily solve the problem. Using v-html to render tags in vueGet the background data with label content, which needs to be rendered to the page for display. The final effect is as follows: Graphics and text layout 1. First get the data and process it separately 2. Then output it in html You may also be interested in:
|
<<: How to completely uninstall iis7 web and ftp services in win7
>>: Solution to 2059 error when connecting Navicat to MySQL
For a website, it is the most basic function. So l...
The fastest way to experience the latest version ...
Table of contents 1. Introduction to import_table...
In design work, I often hear designers participati...
01. Command Overview The paste command will merge...
The specific steps of installing mysql5.7.18 unde...
Problem Description Recently, when I was building...
1. Problem introduction Assume a scenario where a...
If you want to hide content from users of phones, ...
Table of contents summary Overall process front e...
What is a generator? A generator is some code tha...
Implementation ideas First, create a parent conta...
Table of contents Scope Global Scope Function Sco...
Table of contents background 1) Enable the keepch...
nohup Command When using Unix/Linux, we usually w...