简体   繁体   中英

Encoding JSON with spaces in string in PHP from a PHP Session before passing it to Vue.js

I am encoding JSON with spaces in the string in PHP before passing it to Vue.js, however the process is failing. If I test without the spaces everything is fine.

I am sure there is a basic bit of theory than I am just not aware of but if someone could explain that would great.

The encoding code is below:

<?php $f = Session::get('foods');?>

<?php $a = json_encode($f); ?>

Passing to Vue

<credits f = {{$a}} a = {{$b}}  c={{$cr}}></credits>

如果属性可以有空格,则需要在属性两边加上引号。

<credits f='{{$a}}' a='{{$b}}'  c='{{$cr}}'></credits>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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