php+ajax+vue接口

<?php
    $host='localhost';
    $user='shopping';
    $pass='000000';
    $dbname='shopping';
    $link=mysqli_connect($host,$user,$pass,$dbname);

    //这是根据订单号来查寻购物车的信息
    //$sql="select * from order_items where orderid=(select customerid from customers where name='lin')";
    $sql="select * from admin";
    //echo $sql;
    session_start();
    //echo $_SESSION['login'];
    if($_SESSION['login']=='yes'){
        $arr=array();
        $result=mysqli_query($link,$sql);
        // $que=mysqli_fetch_array($result,1);
        while($row=mysqli_fetch_assoc($result)){
            $arr[]=$row;
        }
        echo json_encode($arr);
    }
    
?>
<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>这是购物车</title>
	<link rel="stylesheet" type="text/css" href="js/bootstrap.css" />
	<script src="js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
	<style type="text/css">
		.table-bordered,
		.table>thead:first-child>tr:first-child>th {
			text-align: center;
		}

		thead {
			background-color: #f9f9f9;
		}

		thead th {
			border-bottom: none !important;
		}

		.table-striped>tbody>tr:nth-of-type(odd) {
			background-color: #FFFFFF;
		}

		.table-hover>tbody>tr:hover {
			background-color: #FFFFFF;
		}

		button {
			border: none;
			width: 20px;
		}

		button:active {
			color: #333;
			background-color: #e6e6e6;
			border-color: #adadad;
		}
	</style>
	
</head>

<body>
	<div id="app">
		<table class="table table-bordered table-hover table-striped">
			<thead>
				<!-- <th>订单编号</th>
				<th>书号</th>
				<th>价格</th>
				<th>数量</th>
				<th>总计</th> -->
				<th>账号</th>
				<th>密码</th>
			</thead>
			<tbody>
				<tr v-for="item in items">
					<td>{{item.username}}</td>
					<td>{{item.password}}</td>
					<!-- <td>{{item.orderid}}</td>
					<td>{{item.isbn}}</td>
					<td>{{item.item_price}}</td>
					<td>{{item.quantity}}</td>
					<td>{{item.item_price*item.quantity}}</td> -->
				</tr>
			</tbody>
		</table>
		
		<div class="panel panel-primary">
			<div class="panel-body form-inline" style="text-align: center;">
				<label>
					编号:
					<input type="text" class="form-control">
				</label>

				<label>
					名称:
					<input type="text" class="form-control">
				</label>

				<label>
					口味:
					<input type="text" class="form-control">
				</label>

				<label>
					价格:
					<input type="text" class="form-control">
				</label>

				<!-- 在Vue中,使用事件绑定机制,为元素指定处理函数的时候,如果加了小括号,就可以给函数传参了 -->
				<input type="button" value="添加" class="btn btn-primary">
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	const vm = new Vue({
			el: "#app",
			data: {
				items:[]
			},
			created: function () {
				var that = this;
				$.ajax({
					type: 'POST',
					url: 'shpcar.php',
					success: function (data) {
						var json = JSON.parse(data);
						that.items=json;
					},
				})	
			},
		})	
</script>
</html>

img标签的属性值获取ajax返回的值

<img :src=item.src alt="" width="100px" height="100px"> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值