简体   繁体   English

Vue.js 2自动转义HTML

[英]Vue.js 2 autoescape HTML

I'm using Vue 2 js with Laravel 5.5. 我在Laravel 5.5中使用Vue 2 js。

I have a component data - markdown text. 我有一个组件数据-降价文字。 And I have an vue instance 我有一个vue实例

new Vue({
        el : '#lesson_edit',
        data :  {
            lesson : {
                body : `{{ $lesson->body }}`
           }
        }
    });

Body string has a '>' symbol. 正文字符串带有“>”符号。 But after assign ot escapes to < . 但是分配ot后转义为<。

The problem is the next,I have a vue component, which cconverts markdown to html 问题是下一个,我有一个vue组件,它将c降价转换为html

    <template>
        <div v-html="parsedBody"></div>
    </template>


<script>

    export default {
        props : ['body'],
        mounted() {
            console.log('Component mounted.')
        },
        computed : {
            parsedBody(){
                return marked(this.body, { sanitize: true })
            }
        }
    }
</script>

After assigning body and unescpe, I don't get a valid markdown conversion. 在分配body和unescpe之后,我没有获得有效的降价转换。

WHat should I do? 我该怎么办?

Add somethin to component? 在组件中添加一些东西? Refuse this chars escaping in Vue instance? 拒绝此字符在Vue实例中转义? Or somethin else... Pleas, help. 或者其他...请帮忙。

It is blade engine on server side which escapes html, not Vue. 它是服务器端的刀片引擎,可以转义html,而不是Vue。 You will have to use {!! $lesson->body !!} 您将必须使用{!! $lesson->body !!} {!! $lesson->body !!} instead of {{ $lesson->body }} . {!! $lesson->body !!}而不是{{ $lesson->body }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM