Commit fa4bf9b0 authored by shangbj's avatar shangbj

增加新闻和产品接口

parent 06d54cfd
...@@ -4,10 +4,12 @@ const express = require('express') ...@@ -4,10 +4,12 @@ const express = require('express')
const app = express() const app = express()
// Require API routes // Require API routes
const users = require('./routes/users') const product = require('./routes/product')
const news = require('./routes/news')
// Import API Routes // Import API Routes
app.use(users) app.use(product)
app.use(news)
// Export the server middleware // Export the server middleware
module.exports = { module.exports = {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
const { Router } = require('express')
const newsData = require('./data/news');
const router = Router()
/* GET users listing. */
router.get('/news', function (req, res, next) {
if(req.query.pageSize){
res.json(newsData.slice(0,req.query.page))
}else{
res.json(newsData)
}
})
module.exports = router
\ No newline at end of file
const { Router } = require('express')
const productData = require('./data/product')
const router = Router()
/* GET users listing. */
router.get('/product', function (req, res, next) {
res.json(productData)
})
module.exports = router
\ No newline at end of file
const { Router } = require('express')
const router = Router()
// Mock Users
const users = [
{ name: 'Alexandre' },
{ name: 'Pooya' },
{ name: 'Sébastien' }
]
/* GET users listing. */
router.get('/users', function (req, res, next) {
res.json(users)
})
/* GET user by ID. */
router.get('/users/:id', function (req, res, next) {
const id = parseInt(req.params.id)
if (id >= 0 && id < users.length) {
res.json(users[id])
} else {
res.sendStatus(404)
}
})
module.exports = router
\ No newline at end of file
...@@ -19,10 +19,9 @@ ...@@ -19,10 +19,9 @@
<script> <script>
export default { export default {
data(){ async asyncData({ app }) {
return { const newsData = await app.$axios.$get('/api/news?pageSize=10');
newsData:this.$store.state.news.newsData, return { newsData: newsData }
}
}, },
computed:{ computed:{
optionTop(){ optionTop(){
......
...@@ -102,18 +102,14 @@ import Profile from '~/components/index/Profile.vue' ...@@ -102,18 +102,14 @@ import Profile from '~/components/index/Profile.vue'
import ContactUs from '~/components/ContactUs.vue' import ContactUs from '~/components/ContactUs.vue'
export default { export default {
props:{ async asyncData({ app }) {
const newsData = await app.$axios.$get('/api/news?pageSize=10');
const productData = await app.$axios.$get('/api/product');
return { newsData: newsData,productData:[...productData.ozonizer.data,...productData.disinfectant.data,...productData.equipment.data] }
}, },
data:function(){ data:function(){
return { return {
productData:[
...this.$store.state.product.data.ozonizer.data,
...this.$store.state.product.data.disinfectant.data,
...this.$store.state.product.data.equipment.data,
],
qualificationsData:this.$store.state.qualifications.data, qualificationsData:this.$store.state.qualifications.data,
newsData:this.$store.state.news.newsData,
engineeringData:this.$store.state.engineeringData, engineeringData:this.$store.state.engineeringData,
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment