vue3-example-ssr icon indicating copy to clipboard operation
vue3-example-ssr copied to clipboard

How to invoke a render function in a serverless way

Open acrodrig opened this issue 5 years ago • 1 comments

Hi,

Thanks for the example, it has been very useful. Had a question about generating a render function in a server less manner.

I have a file with simple HTML, such as:

<html>
  <body>Hello</body>
</html>

Then I try to generate a render function via:

import { compile, VNode } from "vue";

const renderFunction = compile(fileContents);
const node: VNode = renderFunction({});

And it works! However I get these warnings:

[Vue warn]: resolveComponent can only be used in render() or setup().
[Vue warn]: resolveComponent can only be used in render() or setup().

Any idea of how to get rid of them?

Thanks a lot!

acrodrig avatar Nov 19 '20 20:11 acrodrig

This is caused by vue runtime, if we take a look at vue source code, you could read this:

function resolveAsset(...) {
  ...
  else if (__DEV__) {
    warn(
      `resolve${capitalize(type.slice(0, -1))} ` +
        `can only be used in render() or setup().`
    )
  }
}

when __DEV__ is true, you will get the warn, so you can change vue runtime to production mode, e.g. set process.env.NODE_ENV = "production"

zhangzhuang15 avatar Aug 23 '23 07:08 zhangzhuang15