Skip to content

引入组件 ​

局部引入

ts
// parent.vue
const FCubicBezier = defineAsyncComponent(() => import('@/components/formaui/f-cubic-bezier/f-cubic-bezier.vue'))

基础用法 ​

贝塞尔曲线飞入动画,常用场景如添加购物车。将组件叠在加购按钮上,点击后徽标沿曲线飞向 position 终点。

html
<view class="add-btn">
  <f-icon name="plus" color="#ffffff" :size="32" />
  <f-cubic-bezier
    :window-width="windowWidth"
    :window-height="windowHeight"
    left="0"
    top="0"
    width="56rpx"
    height="56rpx"
    :position="{ left: 44, bottom: 54 }"
    direction="bottom"
    :index="index"
    :params="item.name"
    @click="addCart" />
</view>
ts
import { onMounted, ref } from 'vue'
import type { FCubicBezierClickDetail } from '@/components/formaui/f-cubic-bezier/types'

const windowWidth = ref(375)
const windowHeight = ref(667)
const cartNum = ref(0)

onMounted(() => {
  const info = uni.getWindowInfo()
  windowWidth.value = info.windowWidth
  windowHeight.value = info.windowHeight
})

const addCart = (detail: FCubicBezierClickDetail) => {
  cartNum.value += 1
  console.log(detail.index, detail.params)
}

direction属性:动画方向(默认down)

可传入[up、down、bottom、top]。括号内为 position 必传字段:up(top, right)、down(right, bottom)、bottom(left, bottom)、top(left, top)

html
<f-cubic-bezier direction="bottom" :position="{ left: 44, bottom: 54 }" />

isCustom属性:是否自定义动画内容(默认false)

html
<f-cubic-bezier is-custom direction="bottom" :position="{ left: 44, bottom: 54 }">
  <f-icon name="bag" color="#ffffff" :size="28" />
</f-cubic-bezier>

插槽 ​

名称说明
default自定义动画内容,需同时设置 isCustom 为 true

属性 ​

名称类型说明默认值
windowWidthnumber屏幕宽度(px),未传时取当前窗口宽度0
windowHeightnumber屏幕高度(px),未传时取当前窗口高度0
widthstring动画内容宽度40rpx
heightstring动画内容高度40rpx
bgColorstring动画内容背景色主题危险色
leftstring相对父级的 left 值0
topstring相对父级的 top 值0
isCustomboolean是否自定义动画内容false
directionstring动画方向,可传入[up、down、bottom、top]:up 右上,down 右下,bottom 左下,top 左上down
positionFCubicBezierPosition动画终点,一般为目标元素中心。按 direction 传入对应字段:top / bottom / left / right,单位 px{ top: 50, bottom: 80, left: 30, right: 40 }
indexnumber列表索引,点击回传0
paramsnumber | string自定义参数,点击回传0

事件 ​

事件名说明回调参数
click点击动画内容时触发{ index: number, params: number | string }

方法 ​

方法名说明传入参数
---