View

视图容器

参考文档

类型

  1. ComponentType<ViewProps>

示例代码

  • React
  • Vue
  1. export default class PageView extends Component {
  2. constructor() {
  3. super(...arguments)
  4. }
  5. render() {
  6. return (
  7. <View className='components-page'>
  8. <Text>flex-direction: row 横向布局</Text>
  9. <View className='flex-wrp' style='flex-direction:row;'>
  10. <View className='flex-item demo-text-1'/>
  11. <View className='flex-item demo-text-2'/>
  12. <View className='flex-item demo-text-3'/>
  13. </View>
  14. <Text>flex-direction: column 纵向布局</Text>
  15. <View className='flex-wrp' style='flex-direction:column;'>
  16. <View className='flex-item flex-item-V demo-text-1'/>
  17. <View className='flex-item flex-item-V demo-text-2'/>
  18. <View className='flex-item flex-item-V demo-text-3'/>
  19. </View>
  20. </View>
  21. )
  22. }
  23. }
  1. <template>
  2. <view class="components-page">
  3. <text>flex-direction: row 横向布局</text>
  4. <view class="flex-wrp flex-wrp-row" hover-class="hover" >
  5. <view class="flex-item demo-text-1" :hover-stop-propagation="true" />
  6. <view class="flex-item demo-text-2" hover-start-time="1000" hover-class="hover" />
  7. <view class="flex-item demo-text-3" hover-stayTime="1000" hover-class="hover" />
  8. </view>
  9. <text>flex-direction: column 纵向布局</text>
  10. <view class="flex-wrp flex-wrp-column">
  11. <view class="flex-item flex-item-V demo-text-1" />
  12. <view class="flex-item flex-item-V demo-text-2" />
  13. <view class="flex-item flex-item-V demo-text-3" />
  14. </view>
  15. </view>
  16. </template>
  17. <style>
  18. .flex-wrp { display: flex; }
  19. .flex-wrp-column{ flex-direction: column; }
  20. .flex-wrp-row { flex-direction:row; padding: 20px; background: #f1f1f1; }
  21. .flex-item { width: 180px; height: 90px; }
  22. .demo-text-1 { background: #ccc; }
  23. .demo-text-2 { background: #999; }
  24. .demo-text-3 { background: #666; }
  25. .hover {
  26. background: #000;
  27. }
  28. </style>

ViewProps

参数类型默认值必填说明
hoverClassstringnone指定按下去的样式类。当 hover-class=”none” 时,没有点击态效果
hoverStylestringnone由于 RN 不支持 Class,故 RN 端的 View 组件实现了 hoverStyle属性,写法和 style 类似,只不过 hoverStyle 的样式是指定按下去的样式。
hoverStopPropagationbooleanfasle指定是否阻止本节点的祖先节点出现点击态
hoverStartTimenumber50按住后多久出现点击态,单位毫秒
hoverStayTimenumber400手指松开后点击态保留时间,单位毫秒
catchMovebooleanfalse阻止滚动穿透

API 支持度

API微信小程序百度小程序支付宝小程序字节跳动小程序H5React Native
ViewProps.hoverClass✔️✔️✔️✔️✔️(由于 RN 不支持 Class,故 RN 端的 View 组件实现了 hoverStyle属性,写法和 style 类似,只不过 hoverStyle 的样式是指定按下去的样式。)
ViewProps.hoverStyle✔️
ViewProps.hoverStopPropagation✔️✔️✔️✔️
ViewProps.hoverStartTime✔️✔️✔️✔️✔️✔️
ViewProps.hoverStayTime✔️✔️✔️✔️✔️✔️

API 支持度

API微信小程序百度小程序支付宝小程序字节跳动小程序H5React Native
View✔️✔️✔️✔️✔️✔️