Node.js/nuxt/组件加载方式:修订间差异
来自康健生活
无编辑摘要 |
|||
| 第58行: | 第58行: | ||
] | ] | ||
})</syntaxhighlight> | })</syntaxhighlight> | ||
==== import ==== | |||
通过 Promise 的 resolve 机制 | |||
<syntaxhighlight lang="javascript"> | |||
import Vue from 'vue' | |||
import Router from 'vue-router' | |||
Vue.use(Router) | |||
const HelloWorld = ()=>import("@/components/HelloWorld") | |||
export default new Router({ | |||
routes: [ | |||
{ | |||
path: '/', | |||
name: 'HelloWorld', | |||
component: HelloWorld | |||
} | |||
] | |||
}) | |||
</syntaxhighlight> | |||
或者 | |||
<syntaxhighlight lang="javascript"> | |||
import Vue from 'vue' | |||
import Router from 'vue-router' | |||
Vue.use(Router) | |||
export default new Router({ | |||
routes: [ | |||
{ | |||
path: '/', | |||
name: 'HelloWorld', | |||
component: ()=>import("@/components/HelloWorld") | |||
} | |||
] | |||
})</syntaxhighlight> | |||
nuxt 抛出错误 | |||
{{Warning|render function or template not defined in component: anonymous}} | |||
== 组件加载 == | |||
== 动态加载组件 == | == 动态加载组件 == | ||
比如现在我有一个需求,需要动态加载画图组件 | 比如现在我有一个需求,需要动态加载画图组件 | ||
| 第84行: | 第127行: | ||
}, | }, | ||
</script></syntaxhighlight> | </script></syntaxhighlight> | ||
除此之外,还可以传参进行加载 | 除此之外,还可以传参进行加载 | ||
<syntaxhighlight lang="html5"> | <syntaxhighlight lang="html5"> | ||
<template> | <template> | ||
| 第127行: | 第155行: | ||
}, | }, | ||
</script></syntaxhighlight> | </script></syntaxhighlight> | ||