Comments (8)
@vuehtml 请给出你期望的使用姿势
from vant.
为了保持原有功能,建议新增一个作用域插槽item
{{item.text}}
from vant.
为了保持原有功能不受影响,建议新增一个item作用域插槽
from vant.
@vuehtml
emmm, 事实上 <VanDropdownItem />
目前就已经支持插槽了,你可以看文档的 DropdownItem Slots 部分,
对应的 demo 是 自定义菜单内容
你提供的代码我给你改写下
<script setup lang="ts">
import { ref } from 'vue';
import { DropdownMenu, DropdownItem } from 'vant';
const item = ref<DropdownItemInstance>();
type Item = { text: string; level: number };
const option1 = ref<Item[]>([
{ text: '包邮', level: 1 },
{ text: '团购', level: 2 },
]);
const selectedItem = ref<Item>(option1.value[0]);
const onConfirm = (it: Item) => {
item.value?.toggle();
selectedItem.value = it;
};
</script>
<template>
当前选中item: {{ selectedItem }}
<van-dropdown-menu>
<van-dropdown-item ref="item" title="筛选">
<p
v-for="(item, index) in option1"
:key="index"
:class="['version-item', { 'padding-level': item.level === 2 }]"
@click="onConfirm(item)"
>
{{ item.text }}
</p>
</van-dropdown-item>
</van-dropdown-menu>
</template>
from vant.
我目前就是这样用的,感觉超级不方便,三大缺点如下:
1:要自己通过ref获取dom,手动触发toggle控制下拉框的显示和隐藏;
2:下拉框的全部样式要自己去写,费时间和精力,本想用组件样式就刚刚好;
3:选中态也要自己去实现,另外选中value对应的text也要自己去数组中查找到,通过title属性展示出来。
我仅仅是想给item修改一点点样式,结果却要付出这么大的精力。所以强烈建议,添加一个作用域插槽,既能避免上述三点恶心的操作,又可以轻松修改item的样式。
目前的vantui仅仅达到可用的标准,距离好用,还有很长的路要走。 例如van-dropdown-menu 还缺少一个自定义key的props属性,真实业务场景当中,option的key可不一定是value和text。当然一个map遍历就可以轻松转换key,但是这样操作浪费性能,尤其是在超级复杂的页面当中。
from vant.
如果提供这个插槽,因为每个用户对样式修改程度的需求不一样,从通用性考虑,插槽会替换整个选项(当前选项是基于 Cell 组件封装的),所以选项的样式还是需要用户去实现。
from vant.
如果提供这个插槽,因为每个用户对样式修改程度的需求不一样,从通用性考虑,插槽会替换整个选项,这句话错了,绝大多数场景,不会替换整个选项,只是对选项文字的样式做修改。
目前的傻大粗default插槽,样式可以自己实现,但是收起和折叠也不能用了,选中态的✔也不能用了,选中项的text也不能展示到title上了,太傻太僵硬了
带复选框的elementui的table组件都用过吧,单元格的横线和样式都还在,插槽修改的是单元格里面的dom样式,表格每行的复选框还在。DropdownMenu和ele-table组件何其相似 呀。这时候用作用域插槽就对了。
from vant.
如果提供这个插槽,因为每个用户对样式修改程度的需求不一样,从通用性考虑,插槽会替换整个选项(当前选项是基于 Cell 组件封装的),所以选项的样式还是需要用户去实现。
看着好像是要把当前子组件项的内容暴露给插槽?#scoped-slots
from vant.
Related Issues (20)
- [Bug Report] van-watermark 组件水印全页显示 HOT 5
- Vant 4.8.11 Highlight 高亮文本 当没有需要高亮的文本时源文本不显示
- [Bug Report] 按需引入vant,showImagePreview样式丢失 HOT 2
- 关于 uniapp HOT 1
- [Bug Report] cascader 默认赋值问题
- 国内站点地址挂了 HOT 9
- [Bug Report]SwipeCell 滑动单元格点击事件错误捕获 HOT 3
- [Bug Report] 关于步进器stepper建议修复下autocomplete问题,应该是默认off或者做成可以配置的 HOT 1
- [Bug Report] useCountDown倒计时总时长被本地时间影响 HOT 1
- [Bug Report] IOS17.4.1版本使用upload组件进行拍照上传的时候会造成页面白屏崩溃 HOT 2
- vant/cli css 打包bug Selector "[data-v-5c89f644]" can't have a suffix
- Gitee 文档站下线通知 & 解决方法 HOT 3
- [Bug Report] IOS 17.4.1 van-uploader 无法选择本地图片
- css样式误差, 感觉像是样式丢失了一样。 HOT 3
- [Bug Report] Area组件中columns-placeholder属性在选择省份和城市数据后出现展示问题 HOT 2
- van-field在自适应高度时,同时添加max-height属性,在超出限高再输入中文时,内容总是滚动到顶部。 HOT 2
- vant-swiper使用动态分页数据,在部分安卓机型,最后一页滑动,会出现白屏
- [Bug Report] vant组件使用插槽以后内部的组件属性watch会有异常问题
- [Bug Report] Tab内嵌套滚动Tab,滚动Tab点击下标响应不正确
- [Bug Report] DropdownMenu 下拉菜单给options属性赋值时采用调用方法的形式时,控制台报警告Uncaught (in promise) Maximum recursive updates exceeded in component <van-dropdown-menu>. This means you have a reactive effect that is mutating its own dependencies and thus recursively triggering itself. Possible sources include component template, render function, updated hook or watcher source function.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vant.