sweet-alert display HTML code in text

前端 未结 11 1351
梦谈多话
梦谈多话 2020-12-24 01:52

I am using sweet-alert plugin to display an alert. With a classical config (defaults), everything goes OK. But when I want to add a HTML tag into the TEXT, it display

11条回答
  •  猫巷女王i
    2020-12-24 02:20

    I just struggled with this. I upgraded from sweetalert 1 -> 2. This library: https://sweetalert.js.org/guides/

    The example from documentation "string" doesn't work as I expected. You just can't put it like this.

    content: `my es6 string template` 
    

    How I solved it:

    const template = (`my es6 string ${variable}`);
    content: {
          element: 'p',
          attributes: {
            innerHTML: `${template}`,
          },
        }
    

    There is no documentation how to do this, it was pure trial and error, but at least seems to work.

提交回复
热议问题