/**
* GET /paragraphs
* Get a range of paragraphs from the specified book
* Query Params -
* bookTitle: string under 256 characters
* start: positive integer
* end: positive integer greater than start
*/
router. get( '/paragraphs',
validate({
query: {
bookTitle: joi. string().max( 256).required(),
start: joi.number().integer().min( 0). default( 0),
end: joi.number().integer().greater(joi. ref( 'start')). default( 10)
}
}),
async(ctx, next) => {
const{ bookTitle, start, end } = ctx.request.query
ctx.body = awaitsearch.getParagraphs(bookTitle, start, end)
}
)
8.2 添加UI界面
本节添加前端查询功能,并显示书中包含查询内容的整页信息。在/public/app.js methods功能块中添加如下内容:
/** Call the API to get current page of paragraphs */
asyncgetParagraphs(bookTitle, offset) {
try{
this.bookOffset = offset
conststart = this.bookOffset
constend = this.bookOffset + 10
constresponse = awaitaxios. get(`${ this.baseUrl}/paragraphs`, { params: { bookTitle, start, end } })
returnresponse.data.hits.hits
} catch(err) {
console.error(err)
}
},
/** Get next page (next 10 paragraphs) of selected book */
asyncnextBookPage() {
this.$refs.bookModal.scrollTop = 0
this.paragraphs = awaitthis.getParagraphs( this.selectedParagraph._source.title, this.bookOffset + 10)
},
/** Get previous page (previous 10 paragraphs) of selected book */
asyncprevBookPage() {
this.$refs.bookModal.scrollTop = 0
this.paragraphs = awaitthis.getParagraphs( this.selectedParagraph._source.title, this.bookOffset - 10)
},
/** Display paragraphs from selected book in modal window */
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-88488-17.html
抗日得时候多少人抵制日货又能怎么样
你有种吗