composition-api.uvue 5.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
  <!-- #endif -->
    <view class="uni-container">
      <uni-collapse>
        <template v-for="item in list" :key="item.id">
          <uni-collapse-item :title="item.name" class="item">
            <view class="uni-navigate-item" :hover-class="page.enable == false ? '' : 'is--active'"
              v-for="(page, key) in item.pages" :key="key" @click="goDetailPage(item.id, page)">
              <text class="uni-navigate-text"
                :class="page.enable == false ? 'text-disabled' : ''">{{ page.name }}</text>
            </view>
          </uni-collapse-item>
        </template>
      </uni-collapse>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

DCloud-WZF's avatar
DCloud-WZF 已提交
23
<script setup lang="uts">
24 25 26 27 28 29 30 31 32 33 34 35 36 37
  type PageItem = {
    name : string
    enable ?: boolean
    url ?: string
  }

  type PageList = {
    id : string
    name : string
    open : boolean
    pages : PageItem[]
    url ?: string
    enable ?: boolean
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
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
  
  const list = [
      {
        id: 'basic',
        name: '基本使用',
        open: false,
        pages: [
          {
            name: 'defineProps',
            url: 'define-props',
            enable: false,
          },
          {
            name: 'defineEmits',
            url: 'define-emits',
            enable: false,
          },
          {
            name: 'defineExpose',
            url: 'define-expose',
            enable: false,
          },
          {
            name: 'defineOptions',
            url: 'define-options',
63
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
          },
          {
            name: 'defineSlots',
            url: 'define-slots',
            enable: false,
          },
          {
            name: 'useSlots',
            url: 'use-slots',
            enable: false,
          },
          {
            name: 'useAttrs',
            url: 'use-attrs',
            enable: false,
          },
        ] as PageItem[],
      }, {
82
        id: 'reactivity',
DCloud-WZF's avatar
DCloud-WZF 已提交
83 84 85 86 87 88
        name: '响应式',
        open: false,
        pages: [
          {
            name: 'ref',
            url: 'ref',
89
            enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
          },
          {
            name: 'computed',
            url: 'computed',
            enable: false,
          },
          {
            name: 'reactive',
            url: 'reactive',
            enable: false,
          },
          {
            name: 'readonly',
            url: 'readonly',
            enable: false,
          },
          {
            name: 'watch',
            url: 'watch',
            enable: false,
          },
          {
            name: 'watchEffect',
            url: 'watch-effect',
            enable: false,
          },
          {
            name: 'watchPostEffect',
            url: 'watch-post-effect',
            enable: false,
          },
          {
            name: 'watchSyncEffect',
            url: 'watch-sync-effect',
            enable: false,
          },
          {
            name: 'isRef',
            url: 'is-ref',
            enable: false,
          },
          {
            name: 'unRef',
            url: 'un-ref',
            enable: false,
          },
          {
            name: 'toRef',
            url: 'to-ref',
            enable: false,
          },
          {
            name: 'toValue',
            url: 'to-value',
            enable: false,
          },
          {
            name: 'toRefs',
            url: 'to-refs',
            enable: false,
          },
          {
            name: 'isProxy',
            url: 'is-proxy',
            enable: false,
          },
          {
            name: 'isReactive',
            url: 'is-reactive',
            enable: false,
          },
          {
            name: 'isReadonly',
            url: 'is-readonly',
            enable: false,
          },
          {
            name: 'shallowRef',
            url: 'shallow-ref',
            enable: false,
          },
          {
            name: 'triggerRef',
            url: 'trigger-ref',
            enable: false,
          },
          {
            name: 'customRef',
            url: 'custom-ref',
            enable: false,
          },
          {
            name: 'shallowReactive',
            url: 'shallow-reactive',
            enable: false,
          },
          {
            name: 'shallowReadonly',
            url: 'shallow-readonly',
            enable: false,
          },
          {
            name: 'toRaw',
            url: 'to-raw',
            enable: false,
          },
          {
            name: 'markRaw',
            url: 'mark-raw',
            enable: false, // 暂不支持
          },
          {
            name: 'effectScope',
            url: 'effect-scope',
            enable: false,
          },
          {
            name: 'getCurrentScope',
            url: 'get-current-scope',
            enable: false,
          },
          {
            name: 'onScopeDispose',
            url: 'on-scope-dispose',
            enable: false,
          },
        ] as PageItem[],
217
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
218 219 220 221 222 223 224 225 226 227
    ] as PageList[]

  const goDetailPage = (id : string, e : PageItem) => {
    if (e.enable == false) {
      uni.showToast({
        icon: 'none',
        title: '暂不支持',
      })
      return
    }
228

DCloud-WZF's avatar
DCloud-WZF 已提交
229 230 231 232
    const url = e.url!.includes('/') ? e.url : `${e.url}/${e.url}`
    uni.navigateTo({
      url: `/pages/composition-api/${id}/${url}`,
    })
233 234 235 236 237 238 239 240
  }
</script>

<style>
  .item {
    margin-bottom: 12px;
  }
</style>