v-bind-options.uvue 1.9 KB
Newer Older
D
DCloud_LXH 已提交
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
<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 :num="dataInfo.fooProps.num" :obj="dataInfo.fooProps.obj" />

    <!-- v-bind in style -->
    <!-- #ifdef WEB -->
    <view class="mb-10 v-bind-css"></view>
    <!-- #endif -->
  </view>
</template>

<script lang="uts">
import Foo from './Foo-options.uvue'

type FooPropsObj = {
  name: string
}
type FooProps = {
  title: string
  num: number
  obj: FooPropsObj
}
type DataInfo = {
  fontSize: string
  backgroundColor: string
  border: string
  fooProps: FooProps
  vBindClassBackgroundColor: string
}

export default {
  components: { Foo },
  data() {
    return {
      title: 'foo title',
      dataInfo: {
        fontSize: '20px',
        backgroundColor: 'background-color: green',
        border: 'border: 2px solid red',
        fooProps: {
          title: '',
          num: 1,
          obj: {
            name: 'foo obj name'
          }
        },
        vBindClassBackgroundColor: 'red'
      } as DataInfo
    }
  }
}
</script>

<style>
/* #ifdef WEB */
.v-bind-css {
  background-color: v-bind(dataInfo.vBindClassBackgroundColor);
  height: 20px;
}
/* #endif */
</style>