vue render html,vue.js - Render Vue component/template to (html) string - Stack Overflow

I'm using a Vue component which expects a string. I like to use template values in the string, but of course is should be XSS safe.

Current unsafe example

This is unsafe, as this.name is unsafe. I could use a NPM package to html encode the name, but I really prefer to use Vue.

import Vue from 'vue';

export default Vue.extend({

props: {

name: { type: String, required: false },

},

methods: {

showModal() {

this.$buefy.dialog.confirm({

title: 'myTitle',

message: `

Hello ${this.name}

`, // unsafe - possible XSS!

cancelText: 'Cancel',

confirmText: 'OK',

type: 'is-success',

onConfirm: async () => {

// something

},

});

},

},

});

This is an issue of the used Buefy component, as documented here:

13t1M.png

Desired Setup

I've created a new component, in this example I call it ModalMessage.Vue

Hello {{name}}

import Vue from 'vue';

export default Vue.extend({

props: {

name: { type: String, required: true },

},

});

Then I like to render the ModalMessage.Vue to a string in Typescript:

import Vue from 'vue';

import ModalMessage from 'ModalMessage.vue';

export default Vue.extend({

props: {

name: { type: String, required: false },

},

methods: {

showModal() {

this.$buefy.dialog.confirm({

title: 'myTitle',

message:, // todo render ModalMessage and pass name prop

cancelText: 'Cancel',

confirmText: 'OK',

type: 'is-success',

onConfirm: async () => {

// something

},

});

},

},

});

Question

How could I render the ModalMessage.Vue, and passing the name prop, to a string?

I'm pretty sure this is possible - I have seen it in the past. Unfortunately I cannot find it on the web or StackOverflow. I could only find questions with rendering a template from string, but I don't need that - it needs to be to string.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值