thinkphp5控制器向+vue的data裏傳值
阿新 • • 發佈:2019-01-12
axios 吐司 body code php5 傳值 type scrip ews
傳一維數組傳值
$array=[‘id‘=>40,"cat_name"=>"明星產品"];
$MenuCats_info=json_encode($array,JSON_UNESCAPED_UNICODE);
$this->assign([
‘MenuCats_info‘=>$MenuCats_info,
]);
return view(‘index‘);
html裏
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>vue</title> <link rel="stylesheet" href=""> <!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>--> <script type="text/javascript" src="__STATIC__/vue/vue.js"></script> <script type="text/javascript" src="__STATIC__/vue/node_modules/axios/dist/axios.js"></script> <style type="text/css"> .success{ color:green; } .error{ color:red; } </style> </head> <body> <div id="vue"> <li v-for="v in news"> <span :class="v.status?‘success‘:‘error‘">{{v.title}}</span> <button v-on:click="changeStatus(v,false)" v-if="v.status">刪除</button> <button v-on:click="changeStatus(v,true)" v-if="!v.status">恢復</button> </li> {{MenuCats_info.cat_name}} </div> </body> <script type="text/javascript"> var app = new Vue({ el: "#vue", data:{ news:[ {title:‘haha‘,status:true}, {title:"hehe",status:true} ], //接收值 |raw 不轉義輸出 MenuCats_info:JSON.parse(‘{$MenuCats_info|raw}‘), } }); </script> </html>
效果:打印
明星產品
傳二維數組:
php裏:
$array=array(
[‘id‘=>35,"cat_name"=>"吐司面包"],
[‘id‘=>40,"cat_name"=>"明星產品"]
);
$MenuCats_info=json_encode($array,JSON_UNESCAPED_UNICODE);
$this->assign([
‘MenuCats_info‘=>$MenuCats_info,
]);
return view(‘index‘);
html裏:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>vue</title> <link rel="stylesheet" href=""> <!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>--> <script type="text/javascript" src="__STATIC__/vue/vue.js"></script> <script type="text/javascript" src="__STATIC__/vue/node_modules/axios/dist/axios.js"></script> <style type="text/css"> .success{ color:green; } .error{ color:red; } </style> </head> <body> <div id="vue"> <li v-for="v in news"> <span :class="v.status?‘success‘:‘error‘">{{v.title}}</span> <button v-on:click="changeStatus(v,false)" v-if="v.status">刪除</button> <button v-on:click="changeStatus(v,true)" v-if="!v.status">恢復</button> </li> <div v-for="vv in MenuCats_info"> {{vv.cat_name}} </div> </div> </body> <script type="text/javascript"> var app = new Vue({ el: "#vue", data:{ news:[ {title:‘haha‘,status:true}, {title:"hehe",status:true} ], //接收值 |raw 不轉義輸出 MenuCats_info:JSON.parse(‘{$MenuCats_info|raw}‘), } }); </script> </html>
thinkphp5控制器向+vue的data裏傳值