feat: 支持间接引用组件#23
Open
F-loat wants to merge 6 commits into
Open
Conversation
Member
Author
|
嗯,不同目录的话会因为文件路径不同导致 hash 值改变,应该也能解决,但是改动估计会多一点了。。 |
Member
Author
|
目前这个同目录是没问题的,组件名涉及了好几个函数,但是总的来说是维护了一个文件路径和组件名的关联对象,文件路径存在就返回组件名,不存在就生成一个新的 hash 值加到文件名后面 |
Member
// index.js
import button from './button.vue'
export default button// main.js
import XButton from './index.js'比如这样,会出问题 |
Member
Author
|
我这边试了下是没问题的,用我那个 it之家 的项目测的 // src/components/index.js
import newsItem from './news-item'
export default newsItem// src/pages/news/list.vue
import newsItem from '@/components' |
Member
|
你那个newsItem的文件名改成别的就出问题,不要 |
Member
Author
|
确实,晚点我再看看有没有别的方式可以实现 |
added 2 commits
May 20, 2018 15:10
Member
Author
|
应该完整支持各种引用方式了 |
added 2 commits
May 20, 2018 16:29
steinslin
reviewed
May 20, 2018
| const source = importsMap[exportsMap[m] || m] | ||
| resolveFn(path.dirname(realSrc), source, (err, realComSrc) => { | ||
| if (err) return reject(err) | ||
| resolve(resolveRealComSrc(realComSrc, exportsMap[m], resolveFn)) |
Member
There was a problem hiding this comment.
这个地方感觉是不是应该这样写
resolveRealComSrc(realComSrc, exportsMap[m], resolveFn).then(resolve).catch(reject)
Member
Author
There was a problem hiding this comment.
嗯,直接 resolve 也行,错误处理我在第一次调用时加一下,这样会有问题不
function resolveSrc (originComponents, components, resolveFn, context) {
return Promise.all(Object.keys(originComponents).map(k => {
return new Promise((resolve, reject) => {
resolveFn(context, originComponents[k].src, (err, realSrc) => {
if (err) return reject(err)
const com = covertCCVar(k)
resolveRealComSrc(realSrc, originComponents[k].module, resolveFn).then(realComSrc => {
const comName = getCompNameBySrc(realComSrc)
components[com] = { src: comName, name: comName }
resolve()
}).catch(reject)
})
})
}))
}
Member
Author
There was a problem hiding this comment.
都加了一下,直接 resolve 好像处理不到错误
Member
Author
Member
|
引一个中间 JS 的目的只是做一个索引?如果是这样,这么玩可以解决一些场景下的问题,但如果是对引用来的 vue 组件有一些操作,那这就就跪了 |
Member
Author
|
一般其实就是索引,为了引用方便,没遇到过做额外处理的情况 |
|
🤔 mpvue引用组件的确实有些问题,虽然js里显示组件是正常的,但实际执行中会报错。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
初步实现了通过
js文件间接引用vue组件,可能需要进一步测试,目前应该要求js文件和vue文件位于同一目录中才行