convert string to Dom in vuejs

后端 未结 3 1304
小鲜肉
小鲜肉 2021-01-17 12:19

recently I want to convert a stirng to Dom in a vue component, but it does\'t work as my expectation. My code looks like this:

  // what I wrote in the templ         


        
3条回答
  •  孤独总比滥情好
    2021-01-17 12:35

    A possible solution is:

    Template:

    {{{libText}}}

    Notice triple {} for get raw html/text interpretation.

    Javascript:

    Vue.component(...  , {
        template: ...  ,
        data: function () {
               return ...     
            }
        },
        computed: {           
            libText:function(){
                // return directly html
                var str="

    some html

    "; return str; } }, methods:{...} });

提交回复
热议问题