vue 2.0渲染html
来源:互联网 发布:视频剪辑制作软件电脑 编辑:程序博客网 时间:2024/05/17 01:05
使用vue添加文本的时候,我们再也不用像jq一样使用append方法插入后台传过来的标签或者数据了。使用v-text
和v-html
我们可以轻松搞定一切。
最近在使用vue渲染一段来自后台文本编译器传过来的数据的时候,发现v-html
不好用了。代码和图示如下:
<div class="protocol-content" v-html="content"></html> new Vue({ el: "#protocol", data() { return { content: null, } }, methods: { // 获取服务协议 getContent: function() { let that = this; let url = `${urlParam.domain()}api/agreement/appRegistAgreement`; axios({ url: url, method: 'get', params: { token: "1632e581-d537-40b0-ad81-215c94280d32" }, }).then(function(res) { const prorocol = res.data.data; that.content = prorocol; }) .catch(function(error) { console.log(error); }); }, }, created() { this.getContent(); } })
兴高采烈的以为结束了,打开chrome发现是这样。。
具体的渲染情况
会惊奇的发现,居然多了引号。。。网上找了一些方法,有一个不错,贴出来分享一下。
这边我们需要对传过来的数据在进行过滤一下
string.replace(prorocol ? /&(?!#?\w+;)/g : /&/g, '&') .replace(/</g, "<") .replace(/>/g, ">") .replace(/"/g, "\"") .replace(/'/g, "\'");
ok,将我的代码修改如下
··· that.content = prorocol.replace(prorocol ? /&(?!#?\w+;)/g : /&/g, '&') .replace(/</g, "<") .replace(/>/g, ">") .replace(/"/g, "\"") .replace(/'/g, "\'");···
ok,成功了! 如图
阅读全文
0 0
- vue 2.0渲染html
- vue 动态渲染 html标签解决方案 v-html
- vue v-html动态添加 html 内容渲染,事件失效(无法从新渲染)
- Vue入门学习-使用服务器传来的JSON数据交给Vue渲染HTML页面
- vue中把字符串带有html标签转为html渲染页面(视频门户网站)
- html渲染
- vue声明式渲染
- vue条件渲染
- vue笔记---条件渲染
- Vue的条件渲染
- Vue-条件渲染
- vue.js条件渲染
- vue 图片渲染
- vue之页面渲染
- 使用v-html解决Vue.js渲染过程中html标签不能被解析(html标签显示为字符串)
- 使用v-html解决Vue.js渲染过程中html标签不能被解析(html标签显示为字符串)
- 在 Express 应用中接入 Vue 2.0 服务端渲染
- 【Vue】 -(6) 条件渲染和列表渲染
- 主键的生成方式有几种?分别是什么?
- linux下IPTABLES配置详解
- mmseg中文分词算法的python实现及其优化
- 作业7
- web前端性能优化总结
- vue 2.0渲染html
- 决策树笔记
- mac 安装vim 插件YouCompleteMe
- C++——跳马问题(广搜)
- 100以内 素数
- 软键盘弹出影响webapp中固定定位的问题
- Lamda Expressions
- java 项目连接mysql 数据库
- $.extend()和$.fn.extend()