如何用Vue.use()载入方式将全局组件改写为长尾?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1687个文字,预计阅读时间需要7分钟。
自定义Vue组件,通常以局部引用方式加载,使用时在应用的组件中通过+import+moduleName+from+%E2%80%98module%27+%E5%AF%BC%E5%85%A5,在components中注册+template+div+class%3D%22app-NewsInfo%22+h3%7B%7Binfo.title%7D%7D%2Fh3+%21--+%E6%96%B0%E9%97%BB%E8%AF%84%E8%AE%BA%E2%80%9D
自定义vue组件,一般是局部引用的方式载入,使用的时候,在应用的组件中使用 import moduleName from ‘module' 导入,在components中注册
<template> <div class="app-NewsInfo"> <h3>{{info.title}}</h3> <!-- 新闻评论子组件。 --> <comment :id="id"></comment> </div> </template> <script> import comment from "../sub/comment.vue"; export default { data() { return { info: {}, id: this.$route.query.id }; }, methods: {}, components: { comment }, </script>
那么如果某个组件经常复用,岂不是每次在新组建中引用都要导入一次吗?是的 。这种情况下可以将组件封装成全局组件,一次导入之后,全局都可以使用。
本文共计1687个文字,预计阅读时间需要7分钟。
自定义Vue组件,通常以局部引用方式加载,使用时在应用的组件中通过+import+moduleName+from+%E2%80%98module%27+%E5%AF%BC%E5%85%A5,在components中注册+template+div+class%3D%22app-NewsInfo%22+h3%7B%7Binfo.title%7D%7D%2Fh3+%21--+%E6%96%B0%E9%97%BB%E8%AF%84%E8%AE%BA%E2%80%9D
自定义vue组件,一般是局部引用的方式载入,使用的时候,在应用的组件中使用 import moduleName from ‘module' 导入,在components中注册
<template> <div class="app-NewsInfo"> <h3>{{info.title}}</h3> <!-- 新闻评论子组件。 --> <comment :id="id"></comment> </div> </template> <script> import comment from "../sub/comment.vue"; export default { data() { return { info: {}, id: this.$route.query.id }; }, methods: {}, components: { comment }, </script>
那么如果某个组件经常复用,岂不是每次在新组建中引用都要导入一次吗?是的 。这种情况下可以将组件封装成全局组件,一次导入之后,全局都可以使用。

