37创客科创中心

 找回密码
 立即注册
查看: 1327|回复: 0

全栈前后端分离示例:python+vuejs pyecharts

[复制链接]

45

主题

84

帖子

909

积分

版主

Rank: 7Rank: 7Rank: 7

积分
909
发表于 2024-8-24 00:27:35 | 显示全部楼层 |阅读模式



前后端全栈示例:
python代码部分:

  1. @app.route('/get823', methods=['GET', 'POST'])
  2. def getlu():
  3.     conn = sqlite3.connect('./instance/API815.db')
  4.     conn.row_factory = sqlite3.Row
  5.     cur = conn.cursor()
  6.     sql = "select * from loginuser"
  7.     rows = cur.execute(sql).fetchall()
  8.     # conn.close()
  9.     rows = [dict(row) for row in rows]
  10.     return jsonify(rows)


  11. @app.route('/823')
  12. def fun823():
  13.     return render_template('index.html', title='823')
复制代码



前端vuejs代码部分:index.html
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport"
  6.           content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8.     <title>37ck</title>
  9.     <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  10.     <script src="https://cdn.jsdelivr.net/npm/vue-resource@1.5.1"></script>
  11. </head>
  12. <body>
  13. <div id="app">
  14.     <h1>Welcome to {{title}}</h1>
  15.     <table border="1" cellpadding="5" cellspacing="5">
  16.         <tr>
  17.             <td>序号</td>
  18.             <td>用户名</td>
  19.             <td>密码</td>
  20.             <td>邮箱</td>
  21.             <td>操作</td>
  22.         </tr>

  23.         <tr v-for="user in users">
  24.             <td>[[user.id]]</td>
  25.             <td>[[user.username]]</td>
  26.             <td>[[user.password]]</td>
  27.             <td>[[user.email]]</td>
  28.             <td>
  29.                 <button @click="editUser(user)">编辑</button>
  30.                 <button @click="deleteUser(user)">删除</button>
  31.             </td>
  32.         </tr>
  33.     </table>
  34. </div>
  35. <script>
  36.     var app = new Vue({
  37.         el: '#app',
  38.         data: {
  39.             users: []
  40.         },
  41.         delimiters: ['[[', ']]'],
  42.         mounted: function () {
  43.             this.getusers()
  44.         },
  45.         methods: {
  46.             getusers() {
  47.                 this.$http.get('/loginusers').then(rsp => {
  48.                     // this.users = rsp.data.results;
  49.                     this.users = rsp.data.results;
  50.                 }, err => {
  51.                     console.log('error')
  52.                 });

  53.             }
  54.         }
  55.     });
  56. </script>
  57. </body>
  58. </html>
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|37创客科创中心

GMT+8, 2025-12-11 18:00 , Processed in 0.187835 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表