$price=$_POST['data'];
$price1=json_decode($price,true);
$price2=$price1['price'];
```javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>商品页面</title>
<script src="../js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
</head>
<body>
<div id="app">
<table>
<tr>
<th>编号</th>
<th>图片</th>
<th>价格</th>
<th>作者</th>
<th>图片路径</th>
</tr>
<tr v-for="item in items">
<td>{{item.id}}</td>
<td>{{item.logo}}</td>
<td>{{item.price}}</td>
<td>{{item.author}}</td>
<td>
<img :src=item.logo alt="" width="100px" height="100px">
</td>
<td><button @click="add(item)">添加购物车</button> </td>
</tr>
</table>
</div>
<script>
new Vue({
el: "#app",
data: {
items:[]
},
created: function () {
var that = this;
$.ajax({
type: 'POST',
url: '../php/showpy.php',
success: function (data) {
var json = JSON.parse(data);
that.items=json;
},
})
},
methods: {
add(item){
let resdata=JSON.stringify(item);
console.log(resdata);
$.ajax({
type: 'POST',
url: '../php/addcar.php',
data:{
data:resdata
},
success: function (data) {
var json=JSON.parse(data);
alert(json);
}
})
}
},
})
</script>
</body>
</html>
当前没有用户登录时,访问该页面,直接跳转到登录页面
created: function () {
var that = this;
$.ajax({
type: 'POST',
url: '../php/shpcar.php',
success: function (data) {
var json = JSON.parse(data);
if(json.flag){
that.items=json;
}else{
location.href='../html/login.html';
}
},