How to get Database data in asyncData by vue ssr

  1. asyncData runs on the server, cannot be requested with ajax, is already running on the server, and does not require ajax.
  2. you cannot require mongo a database in entry-server.js,
  3. where should I execute the query command of mongodb and send the data to asyncData?
  4. is it possible to put data into context in front of the render page?
const baseRender = async function(ctx, next){
    let context = {url: ctx.request.url};
    let htmlStr = await new Promise((resolve, reject) => {
        renderer.renderToString(context, (err, html) => {
      if (err) {
        reject(err)
      }
      resolve(html);
    });
    }).catch(e => {
        console.error(e);
        return e;
    });
    if (htmlStr.code && htmlStr.code === 404) {
        await next();
    } else {
        ctx.body = htmlStr;
    }
    
}
Mar.29,2022

make requests in asyncData, but not with ajax, but with http in node. You can directly axios libraries, be compatible with browsers and node.js

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2eb0d-2bc44.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2eb0d-2bc44.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?