在 Laravel Blade 中转义 VueJS 数据绑定语法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37934124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Escape VueJS data binding syntax in Laravel Blade?
提问by Gus
Laravel templating language Blade and VueJS data binding syntax are very similar.
Laravel 模板语言 Blade 和 VueJS 数据绑定语法非常相似。
How can I escape VueJS data binding syntax when in a *.blade.php
file?
如何在*.blade.php
文件中转义 VueJS 数据绑定语法?
Example:
例子:
<div>
<!-- Want it with VueJS -->
{{ selectedQuestionDesc }}
</div>
<div>
<!-- Want it with Laravel Blade -->
{{ $selectedQuestionDesc }}
</div>
回答by Gus
While asking the question I discovered that you can escape Laravel's Blade by prepending an @
sign before the double brackets {{}}
or the {!! !!}
html rendering brackets.
在问这个问题时,我发现你可以通过@
在双括号{{}}
或{!! !!}
html 渲染括号前加上一个符号来逃避 Laravel 的刀片。
So here is the answer:
所以这里是答案:
<div>
<!-- HTML rendering with VueJS -->
@{{ selectedQuestionDesc }}
<!-- Data binding with VueJS -->
@{{ selectedQuestionDesc }}
</div>
<div>
<!-- HTML with Laravel Blade -->
{!! $selectedQuestionDesc !!}
<!-- Variable binding with Laravel Blade -->
{{ $selectedQuestionDesc }}
</div>
回答by Afraz Ahmad
In order to output real HTML, you will need to use the v-html directive:
为了输出真正的 HTML,你需要使用 v-html 指令:
<p>Using v-html directive: <span v-html="rawHtml"></span></p>