v-bind-composition.uvue 2.0 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<template>
  <view class="page">
    <!-- v-bind attribute -->
    <button id="disabled-btn" class="mb-10" :disabled="true">
      :disabled true
    </button>
    <button id="v-bind-disabled-btn" class="mb-10" v-bind:disabled="false">
      v-bind:disabled false
    </button>

    <!-- v-bind style -->
    <view class="flex justify-between flex-row mb-10">
      <text>bind object style fontSize:</text>
      <text id="bind-object-style" :style="{ fontSize: dataInfo.fontSize }">
        {{ dataInfo.fontSize }}
      </text>
    </view>
    <view
      id="bind-array-style"
      class="mb-10 p-10"
      :style="[dataInfo.backgroundColor, dataInfo.border]">
      <view>bind arr style</view>
      <view class="my-10">{{ dataInfo.backgroundColor }}</view>
      <view>{{ dataInfo.border }}</view>
    </view>

    <!-- v-bind props -->
    <Foo
      :title="dataInfo.fooProps.title"
      :num="dataInfo.fooProps.num"
      :obj="dataInfo.fooProps.obj" />

33 34 35
    <!-- v-bind props -->
    <Foo checked />

DCloud-WZF's avatar
DCloud-WZF 已提交
36 37 38 39 40 41 42 43 44
    <!-- v-bind in style -->
    <!-- #ifdef WEB -->
    <view class="mb-10 v-bind-css"></view>
    <!-- #endif -->
  </view>
</template>

<script setup lang="uts">
import Foo from './Foo-composition.uvue'
DCloud-WZF's avatar
DCloud-WZF 已提交
45
import {type FooPropsObj} from './Foo-composition.uvue'
DCloud-WZF's avatar
DCloud-WZF 已提交
46 47 48 49 50 51 52 53 54 55 56 57

type FooProps = {
  title : string
  num : number
  obj : FooPropsObj
}
type DataInfo = {
  fontSize : string
  backgroundColor : string
  border : string
  fooProps : FooProps
  vBindClassBackgroundColor : string,
58
  vBindClassRpxHeight : string,
DCloud-WZF's avatar
DCloud-WZF 已提交
59 60 61 62 63 64 65 66 67 68 69
}

const dataInfo = reactive({
  fontSize: '20px',
  backgroundColor: 'background-color: green',
  border: 'border: 2px solid red',
  fooProps: {
    title: 'foo title',
    num: 1,
    obj: {
      name: 'foo obj name',
DCloud-WZF's avatar
DCloud-WZF 已提交
70
    } as FooPropsObj
DCloud-WZF's avatar
DCloud-WZF 已提交
71 72
  },
  vBindClassBackgroundColor: 'red',
73
  vBindClassRpxHeight: '300rpx'
DCloud-WZF's avatar
DCloud-WZF 已提交
74 75 76 77 78 79 80 81 82 83 84
} as DataInfo)

defineExpose({
  dataInfo
})
</script>

<style>
/* #ifdef WEB */
.v-bind-css {
  background-color: v-bind(dataInfo.vBindClassBackgroundColor);
85
  height: v-bind(dataInfo.vBindClassRpxHeight);
DCloud-WZF's avatar
DCloud-WZF 已提交
86 87 88
}
/* #endif */
</style>