dsgdfh302506 2019-07-14 07:37
浏览 367

Vue prop - 在字符串[duplicate]中传递单引号和双引号

The problem

I have a string like this (containing: both single and double quotes).

She said: "Hey! That's my bike!!"

I need it to be a title in a Vue component. I could pass it into a slot, but for other reasons, it would be awesome if I could pass it into a prop, as such:

<?php
$title = "She said: \"Hey! That's my bike!!\""
?>
<page-object
  title="<?php echo $title; ?>"
>
</page-object>

Solution-attempts

Attempt1: I've tried escaping the quotation-marks, but that doesn't work. Like this:

<page-object
  title="Hey, single quote: ' and double quote: \" ... Doesn't work!"
>
</page-object>

Attempt2: I could live without double-quotes, and do something like this:

<?php
$title = "She said: \"Hey! That's my bike!!\""
$title = str_replace( '"', "'", $title );
?>
<page-object
  title="<?php echo $title; ?>"
>
</page-object>

... but it's not ideal, since it's the end-users setting that page title. So it's kinda crap disallowing/automatically replacing this one (quite oftenly used) character.

Attempt3: JSON-encode it, but that generates a long string and I need to utilize the solution from attempt2, in order to make this work anyway. So it still doesn't make it possible to have both single and double quotes in the page titles.


Ideally, I'm looking for a magical function, that I can run any string through in PHP, outputting a JSON-object. That I can then pass as a prop and parse inside my Vue Component, ensuring that both single and double quotes can squeeze through that keyhole.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿