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.
Why
有项目不要自动填充的功能
How
一、抽离纯函数到utils
方便添加测试和理解函数用途;简化vue文件
二、变values为计算属性
indexes是选中的索引;values是选中的值。这两个需要同时维护,非常容易出错。
这里将values变为indexes的计算属性。只需要维护indexes即可,简化大量代码
三、添加autoFill属性
这个属性其实影响了两个功能:
a. 都没选时,只有一个省选择框
b. 选了省,则多一个市选择框
c. 选了市,则多一个区选择框
d. 此时重新选省,则区选择框消失,只剩市选择框
但目前项目同时需要这两个功能,这里先把它们都归于autoFill属性
当设置autoFill为false时,会影响两处:
但此时出现了bug,经排查是setValue的问题
四、整理setValue逻辑
这个函数本质是将value里的省、市、区值,反映到三个选择框的可选项和已选中项
a. 如果不合法,设置市、区列表为空,设置省、市、区选中项为空。函数立即return
b. 如果合法,设置省选中项,设置对应市列表,并继续
a. 如果不合法,设置区列表为空,设置市、区选中项为空。函数立即return
b. 如果合法,设置市选中项,设置对应区列表,并继续
a. 如果不合法,设置区选中项为空
b. 如果合法,设置区选中项
逻辑整理完毕,也就fix #46
Test
Docs
新增auto-fill文档和示例