Thinkphp template directly assigns an array to js

1. In the controller

$arr = [
    'code' => 1,
    'msg' => '测试信息',
    'data' => [
        'mmcike', 'ncaa'
    ]
];
$this->assign('arr', $arr);

2. In js

let arr = <?=json_encode($arr)?>;
console.log(arr);

3. The output result is shown in the figure:

Guess you like

Origin blog.csdn.net/zhunju0089/article/details/109039818