Ver código fonte

[add] getDetial

wenliming 3 anos atrás
pai
commit
8d53477c6c
5 arquivos alterados com 108 adições e 4 exclusões
  1. 10 0
      nuxt.config.js
  2. 2 1
      package.json
  3. 20 0
      pages/home/_id.vue
  4. 68 2
      pages/index.vue
  5. 8 1
      yarn.lock

+ 10 - 0
nuxt.config.js

@@ -39,5 +39,15 @@ export default {
 
   // Build Configuration: https://go.nuxtjs.dev/config-build
   build: {
+  },
+  
+  router: {
+    extendRoutes(routes, resolve) {
+      routes.push({
+        name: 'index',
+        path: '/:id?',
+        component: resolve(__dirname, 'pages/index.vue')
+      })
+    }
   }
 }

+ 2 - 1
package.json

@@ -17,6 +17,7 @@
     "test": "jest"
   },
   "dependencies": {
+    "axios": "^0.26.1",
     "bootstrap": "^4.6.1",
     "bootstrap-vue": "^2.21.2",
     "core-js": "^3.19.3",
@@ -34,4 +35,4 @@
     "jest": "^27.4.4",
     "vue-jest": "^3.0.4"
   }
-}
+}

+ 20 - 0
pages/home/_id.vue

@@ -0,0 +1,20 @@
+<template>
+  <div>
+  </div>
+</template>
+
+<script>
+export default {
+	name: "index",
+  data () {
+		return {
+    }
+  },
+  mounted () {
+	}
+}
+</script>
+
+<style scoped>
+
+</style>

+ 68 - 2
pages/index.vue

@@ -1,9 +1,75 @@
 <template>
-  <Tutorial/>
+  <div>
+    {{JSON.stringify(detail)}}
+  </div>
 </template>
 
 <script>
+import axios from 'axios';
+
 export default {
-  name: 'IndexPage'
+	name: "index",
+	data () {
+		return {
+			detail: {},
+			title: '',
+			twitterTitle: '',
+			jumpUrl: ''
+		}
+	},
+
+	head() {
+		return {
+			type: '',
+			title: this.title,
+			meta: [
+				{
+					name: 'twitter:card',
+					content: 'summary_large_image'
+				},
+				{
+					name: 'twitter:url',
+					content: this.jumpUrl
+				},
+				{
+					name: 'twitter:title',
+					content: this.twitterTitle
+				},
+				{
+					name: 'twitter:image',
+					content: this.detail.postBizData.imagePath || ''
+				},
+				{
+					name: 'twitter:image:width',
+					content: '1280'
+				},
+				{
+					name: 'twitter:image:height',
+					content: '720'
+				},
+			]
+		}
+	},
+  async asyncData (params) {
+     let {route} = params;
+		 let {data} = await axios.post('https://denettestapi.piaoquantv.com/denet/post/getDetail', {
+			baseInfo: {
+				token: ''
+      },
+			params: {
+				postId: route.params.id || ''
+			}
+		})
+		if (data.data && data.data.postBizData && typeof data.data.postBizData == 'string') {
+			data.data.postBizData = JSON.parse(data.data.postBizData)
+		}
+		return {
+			detail: data.data,
+		}
+  }
 }
 </script>
+
+<style scoped>
+
+</style>

+ 8 - 1
yarn.lock

@@ -2359,6 +2359,13 @@ axios@^0.21.0:
   dependencies:
     follow-redirects "^1.14.0"
 
+axios@^0.26.1:
+  version "0.26.1"
+  resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
+  integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
+  dependencies:
+    follow-redirects "^1.14.8"
+
 babel-code-frame@^6.26.0:
   version "6.26.0"
   resolved "https://registry.npmmirror.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
@@ -4577,7 +4584,7 @@ flush-write-stream@^1.0.0:
     inherits "^2.0.3"
     readable-stream "^2.3.6"
 
-follow-redirects@^1.14.0:
+follow-redirects@^1.14.0, follow-redirects@^1.14.8:
   version "1.14.9"
   resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
   integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==