|
|
前后端全栈示例:
python代码部分:
- @app.route('/get823', methods=['GET', 'POST'])
- def getlu():
- conn = sqlite3.connect('./instance/API815.db')
- conn.row_factory = sqlite3.Row
- cur = conn.cursor()
- sql = "select * from loginuser"
- rows = cur.execute(sql).fetchall()
- # conn.close()
- rows = [dict(row) for row in rows]
- return jsonify(rows)
- @app.route('/823')
- def fun823():
- return render_template('index.html', title='823')
复制代码
前端vuejs代码部分:index.html
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport"
- content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>37ck</title>
- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/vue-resource@1.5.1"></script>
- </head>
- <body>
- <div id="app">
- <h1>Welcome to {{title}}</h1>
- <table border="1" cellpadding="5" cellspacing="5">
- <tr>
- <td>序号</td>
- <td>用户名</td>
- <td>密码</td>
- <td>邮箱</td>
- <td>操作</td>
- </tr>
- <tr v-for="user in users">
- <td>[[user.id]]</td>
- <td>[[user.username]]</td>
- <td>[[user.password]]</td>
- <td>[[user.email]]</td>
- <td>
- <button @click="editUser(user)">编辑</button>
- <button @click="deleteUser(user)">删除</button>
- </td>
- </tr>
- </table>
- </div>
- <script>
- var app = new Vue({
- el: '#app',
- data: {
- users: []
- },
- delimiters: ['[[', ']]'],
- mounted: function () {
- this.getusers()
- },
- methods: {
- getusers() {
- this.$http.get('/loginusers').then(rsp => {
- // this.users = rsp.data.results;
- this.users = rsp.data.results;
- }, err => {
- console.log('error')
- });
- }
- }
- });
- </script>
- </body>
- </html>
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|