Browse Source

change title by wx.setNavigationBarTitle

charblus 5 years ago
parent
commit
6ecd54158d
4 changed files with 48 additions and 3 deletions
  1. 11 0
      README.md
  2. 9 0
      server/controllers/bookdetail.js
  3. 13 0
      src/components/BookInfo.vue
  4. 15 3
      src/pages/detail/Detail.vue

+ 11 - 0
README.md

@@ -36,3 +36,14 @@ npm run build --report
 
 For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
 
+
+### mysql语句
+
+Mysql 基本语法
+
+`create  database 数据库名;`    创建数据库
+`show tables; `                查看数据库所有表
+`desc   表名;`           查看数据表
+`alter table books add column count int default 0;`    在books表中添加count  int类型 默认0;
+`select title, count from books; `   查看books表部分数据
+`show create table books;`     查看创建books用了哪些语句

+ 9 - 0
server/controllers/bookdetail.js

@@ -2,6 +2,15 @@ const {mysql} = require('../qcloud')
 
 module.exports = async (ctx) => {
   const {id} = ctx.request.query
+  const detail = await mysql('books')
+                       .select()
+                       .where('id', id)
+                       .first()
+
+  // console.log(detail)
+  ctx.state.data = detail
+
+  // 浏览量+1
   await mysql('books')
           .where('id', id)
           .increment('count', 1)

+ 13 - 0
src/components/BookInfo.vue

@@ -0,0 +1,13 @@
+<template>
+  <div>
+      <img class="img" :src="info.image"  mode='aspectFit'>
+  </div>
+</template>
+<script>
+export default {
+  props: ['info']
+}
+</script>
+<style>
+
+</style>

+ 15 - 3
src/pages/detail/Detail.vue

@@ -1,18 +1,30 @@
 <template>
-  <div>图书id{{bookid}}</div>
+  <div>
+    图书id{{bookid}}
+    <BookInfo :info='info'></BookInfo>
+  </div>
 </template>
 <script>
-import {get} from '@/util'
+import {get} from '@/util';
+import BookInfo from '@/components/BookInfo'
 export default {
+  components: {
+    BookInfo
+  },
   data() {
     return {
-      bookid: ''
+      bookid: '',
+      info: {}
     }
   },
   methods: {
     async getDetail() {
       const info = await get('/weapp/bookdetail', {id: this.bookid})
+      wx.setNavigationBarTitle({
+        title: info.title
+      })
       console.log(info);
+      this.info = info;
    }
   },
   mounted() {