1、vue发送axios请求
2、php接收请求并获取数据库
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
if(isset($_GET["id"])){
$id=$_GET["id"];
$sql="SELECT * FROM article where article_id=".$id;
}else{
$sql="SELECT * FROM article ORDER BY article_time DESC";
}
$conn = new mysqli("localhost", "root", "960607", "blogs");
$result = $conn->query($sql);
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "") {$outp .= ",";}
$text = preg_replace("/\s/is", "", $rs["article_text"]);
$content = preg_replace("/\s/is", "", $rs["article_content"]);
$outp .= '{"id":"' . $rs["article_id"] . '",';
$outp .= '"top":"' . $rs["article_top"]. '",';
$outp .= '"category":"' .$rs["article_category"]. '",';
$outp .= '"read":"' .$rs