ctx.body = await service.get_search_data(start,count,keyword,(err,res)=>{
if(err){
return "";
}else {
return res;
}
}
)
The res in the callback function can accept the data, so why can"t the ctx.body accept it?
ctx.body = await service.get_search_data(start,count,keyword,(err,res)=>{
if(err){
return "";
}else {
return res;
}
}
)
The res in the callback function can accept the data, so why can"t the ctx.body accept it?
ctx.body = await new Promise((resolve, reject) => {
service.get_search_data(start, count, keyword, (err, res) => err ? reject(err) : resolve(res))
})
Previous: The content of element-ui table is not centered vertically
Next: Could you tell me how to write the SQL of the top 10 users who get the order amount?
my page uses the views layouts index.hbs template, in which there are three links corresponding to three pages. The question now is: how can I get the current path, because I want to set the active class name to the corresponding link according to t...
question 1: why is the middleware in the koa2 framework written in the form of async, rarely in Synchronize mode (that is, without async)? For example, app.use(async (ctx, next) => { const start = new Date() await next() const ms = new Date() ...
several interfaces are written with koa+mongodb. Cross-domain errors are always reported when requesting with ajax, even if cors is used in koa. Google has done a lot of things but still hasn t solved the problem . const cors = require( koa2-cors ); ...
for example, the front and rear separation project vue + axios + koa2 + java (springboot) uses restful style api question: what role does koa2 play? Specifically, what code should be written in koa2? Under the vue+koa2 front-end combination, where...
ctx.set( Content-disposition , attachment; filename=district.csv ); ctx.set( content-type , text csv; charset=utf-8 ); ctx.statusCode = 200; ctx.body = csv; set excel to open or garbled in this way ...
I would like to ask you bosses about the problems in the direction of learning how to learn Node has always been my doubt. The blogs and tutorials I read on the Internet are all about learning several core modules of Nodejs (fs,path,event,buffer,http)...
A server built with koa2 wants to use koa-faivcon to load page logo, but it doesn t work. Does this middleware depend on anything else? < hr > Project directory is as follows: reference code is as follows: app.use(favicon(resolve( . publ...
1. First of all, get the order list through the query, and then add the user name and user password for each order object through the for loop. When I console.log, the console has output, but when I, ctx.body = {data:orderList}, the result obtained asyn...
the subject has just learned node and back-end knowledge. There was a problem when combining the previous todolist written in vue with the back-end code (login section). Front end Code-vue methods methods: { checkHasLogin () { axios.get( ...
require( babel-register ) const express = require( express ) const webpack = require( webpack ) const webpackConfig = require( . webpack.config ) const app = express() webpack var compiler = webpack(webpackConfig); webpack-dev-server var ...
router.get( meibrain , async (ctx, next) => { await ctx.render( meibrain , { imgSrc: images newsbannenr.png , koa-router }) })...
const MongoClient = require( mongodb ).MongoClient; const url = mongodb: localhost:27017 ; Database Name const dbName = youyue ; var obj = {}; module.exports = async(ctx,next)=>{ const num = ctx.query.num, page = ctx.query.pag...
RT Route is: koa-router A parameter is handwritten in the browser address bar, which can be obtained by the server. It is written on the a tag but reported 400 ....
how to get controllers frontListNewsCenter.js data in router.get ( ) of routes news.js routes news.js const router = require( koa-router )({ prefix: news }) const config = require( .. config ) const controllers = require...
I fumbled to do web development with koa2, and now I find that the front desk is unable to request data. I would like to ask what is unreasonable? controllers page.js models pageModel.js public routes index.js views page.ejs app.j...
how to deal with it generally, all I can think of is to do some interfaces on the node server, as shown in the following figure: routes news.js const router = require( koa-router )({ prefix: news }) const config = require( .. config ) ...
how does RT:koa2 manage api routing and page routing? ...
is it necessary for RT: to do this? if you don t think this is necessary, how can koa-router standardize the interface path and html path? ...
the business you want to achieve is to render the page first, and then add content to the page through ctx.body the core code is as follows await ctx.render( crawler , { title: , content: `<h2>< h2> <h4>...
is there any difference below? controllers async function get (ctx, next) { const res = await models.test.get() ctx.state.data = res.data ******* ******** ctx.body = res.data await next() } module.exports = { ge...