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

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 如何用stata画出文献中常见的安慰剂检验图
    • ¥15 c语言链表结构体数据插入
    • ¥40 使用MATLAB解答线性代数问题
    • ¥15 COCOS的问题COCOS的问题
    • ¥15 FPGA-SRIO初始化失败
    • ¥15 MapReduce实现倒排索引失败
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型