当前位置: 首页 > wzjs >正文

网站淘宝客一般怎么做手机装修设计软件app

网站淘宝客一般怎么做,手机装修设计软件app,微网站微商城建设,企业高端网站制作后端&#xff08;PHP&#xff09; 首先&#xff0c;我们需要一个简单的PHP后端来处理增删改查操作。假设我们有一个名为items的表&#xff0c;包含id、name和description字段。 1. 数据库连接 创建一个db.php文件来处理数据库连接&#xff1a; <?php $host localhost;…

后端(PHP)

首先,我们需要一个简单的PHP后端来处理增删改查操作。假设我们有一个名为items的表,包含idnamedescription字段。

1. 数据库连接

创建一个db.php文件来处理数据库连接:

<?php
$host = 'localhost';
$dbname = 'your_database_name';
$username = 'your_username';
$password = 'your_password';try {$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {die("Could not connect to the database $dbname :" . $e->getMessage());
}
?>
2. CRUD操作

创建一个api.php文件来处理CRUD操作:

<?php
require 'db.php';header("Content-Type: application/json; charset=UTF-8");$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', trim($_SERVER['PATH_INFO'], '/'));if ($request[0] === 'items') {switch ($method) {case 'GET':if (isset($request[1])) {$stmt = $pdo->prepare("SELECT * FROM items WHERE id = ?");$stmt->execute([$request[1]]);$item = $stmt->fetch(PDO::FETCH_ASSOC);echo json_encode($item);} else {$stmt = $pdo->query("SELECT * FROM items");$items = $stmt->fetchAll(PDO::FETCH_ASSOC);echo json_encode($items);}break;case 'POST':$data = json_decode(file_get_contents("php://input"), true);$stmt = $pdo->prepare("INSERT INTO items (name, description) VALUES (?, ?)");$stmt->execute([$data['name'], $data['description']]);echo json_encode(['id' => $pdo->lastInsertId()]);break;case 'PUT':$data = json_decode(file_get_contents("php://input"), true);$stmt = $pdo->prepare("UPDATE items SET name = ?, description = ? WHERE id = ?");$stmt->execute([$data['name'], $data['description'], $request[1]]);echo json_encode(['success' => true]);break;case 'DELETE':$stmt = $pdo->prepare("DELETE FROM items WHERE id = ?");$stmt->execute([$request[1]]);echo json_encode(['success' => true]);break;}
}
?>

前端(Vue 3)

接下来,我们使用Vue 3来创建一个简单的用户界面来处理增删改查操作。

1. 安装Vue 3

首先,确保你已经安装了Vue CLI。如果没有,可以使用以下命令安装:

npm install -g @vue/cli

然后创建一个新的Vue项目:

vue create vue-crud
cd vue-crud
2. 创建组件

src/components目录下创建一个ItemList.vue组件:

<template><div><h1>Items</h1><ul><li v-for="item in items" :key="item.id">{{ item.name }} - {{ item.description }}<button @click="editItem(item)">Edit</button><button @click="deleteItem(item.id)">Delete</button></li></ul><form @submit.prevent="addItem"><input v-model="newItem.name" placeholder="Name" required /><input v-model="newItem.description" placeholder="Description" required /><button type="submit">Add Item</button></form></div>
</template><script>
import axios from 'axios';export default {data() {return {items: [],newItem: { name: '', description: '' },};},methods: {async fetchItems() {const response = await axios.get('http://localhost/api.php/items');this.items = response.data;},async addItem() {const response = await axios.post('http://localhost/api.php/items', this.newItem);this.items.push({ id: response.data.id, ...this.newItem });this.newItem = { name: '', description: '' };},async editItem(item) {const updatedName = prompt('Enter new name', item.name);const updatedDescription = prompt('Enter new description', item.description);if (updatedName && updatedDescription) {await axios.put(`http://localhost/api.php/items/${item.id}`, {name: updatedName,description: updatedDescription,});item.name = updatedName;item.description = updatedDescription;}},async deleteItem(id) {await axios.delete(`http://localhost/api.php/items/${id}`);this.items = this.items.filter(item => item.id !== id);},},created() {this.fetchItems();},
};
</script>
3. 在主应用中使用组件

src/App.vue中使用ItemList组件:

<template><div id="app"><ItemList /></div>
</template><script>
import ItemList from './components/ItemList.vue';export default {name: 'App',components: {ItemList,},
};
</script>
4. 运行应用

最后,运行Vue应用:

npm run serve

现在,你应该能够在浏览器中访问http://localhost:8080,并看到一个简单的增删改查界面。

总结

这个示例展示了如何使用PHP和Vue 3实现一个基本的增删改查功能。你可以根据需要扩展这个示例,例如添加表单验证、分页、排序等功能。


文章转载自:

http://OOTHIpFr.tqLhn.cn
http://VUigUznZ.tqLhn.cn
http://grtEi1X7.tqLhn.cn
http://YY78Wti9.tqLhn.cn
http://2ohHPlaL.tqLhn.cn
http://LZmWQUY2.tqLhn.cn
http://t1iRBB1T.tqLhn.cn
http://SpFnIM0k.tqLhn.cn
http://4Ey72rhf.tqLhn.cn
http://a4Dc1bk5.tqLhn.cn
http://HzT6hUCV.tqLhn.cn
http://6krOl3pi.tqLhn.cn
http://sZsyNITo.tqLhn.cn
http://Q6VomaSJ.tqLhn.cn
http://egzeQzlf.tqLhn.cn
http://2Cp6Ot8U.tqLhn.cn
http://eSOP0AeC.tqLhn.cn
http://SprZSnJO.tqLhn.cn
http://anBtF00d.tqLhn.cn
http://yOZoTk7n.tqLhn.cn
http://sBGBArL8.tqLhn.cn
http://JaqKKhoS.tqLhn.cn
http://bBKSA1JR.tqLhn.cn
http://OFqRbEVI.tqLhn.cn
http://TnFnlnqR.tqLhn.cn
http://G9yNZ2pW.tqLhn.cn
http://nMMUjqvl.tqLhn.cn
http://ApqGh1cb.tqLhn.cn
http://NTyR59cZ.tqLhn.cn
http://XPnepFrv.tqLhn.cn
http://www.dtcms.com/wzjs/610384.html

相关文章:

  • 确定网站文案简单asp网站源码
  • 在哪个网站做视频可以赚钱网站发布与推广方式
  • 事业单位网站方案wordpress即时聊天插件
  • 成都网站开发公司绍兴柯桥哪里有做网站的
  • 商业网站建设与运营运行下打开wordpress
  • 网站架设建设wdcp更改网站域名
  • 做基因结构可以用哪个网站茌平网站制作
  • 百度做网站 推广费用怎么收河北邯郸中考成绩公布时间
  • 杭州网络科技网站建设wordpress myisam
  • 福州外贸网站建设工厂的网站在哪里做的
  • 做网站需要什么资质做网站 广州
  • 网站维护的内容和步骤百度云网盘免费资源
  • 北京市住房及城乡建设部网站企业网站建设的重要性
  • 易语言可以做网站了吗汕头个人网站推广建设
  • 南宁做网站方案品牌营销专家
  • 信息发布型网站是企业网站的什么推广链接代点
  • 天津 交友 网站建设企业网站建设视频
  • 毕业设计网站开发杭州 平台 公司 网站建设
  • 医院网站主页面设计地方门户网站域名
  • 甜蜜高端定制网站wordpress主题 四亩地
  • 网站建设相关新闻学校校园网站建设服务
  • 网站建设工作稳定吗ui设计师面试问题及答案
  • 档案网站建设的步骤网站如何做美工
  • wordpress语言切换网站个体营业执照可以做网站嘛
  • 武进网站建设价位怎么查看网站是否被百度收录
  • 标志空间网站什么网站的新闻做参考文献
  • 网站运营怎样做免费广告推广平台
  • 广东专业网站开发还能用的wap网站
  • 网站备案 信息安全管理协议企业网站怎么搭建
  • 制作图片和视频一起的软件如何查看网站seo