options-api.uvue 12.6 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1
<template>
2
  <!-- #ifdef APP -->
DCloud-WZF's avatar
DCloud-WZF 已提交
3
  <scroll-view style="flex: 1">
DCloud-WZF's avatar
DCloud-WZF 已提交
4
  <!-- #endif -->
5
    <view class="uni-container">
DCloud-WZF's avatar
DCloud-WZF 已提交
6 7 8 9 10 11 12 13 14 15 16
      <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>
17
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
18
  <!-- #ifdef APP -->
19 20
  </scroll-view>
  <!-- #endif -->
DCloud-WZF's avatar
DCloud-WZF 已提交
21 22
</template>

23
<script lang="uts">
24
  import { setLifeCycleNum, state } from '@/store/index.uts'
DCloud-WZF's avatar
DCloud-WZF 已提交
25

26 27 28 29 30
  type PageItem = {
    name : string
    enable ?: boolean
    url ?: string
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
31

32 33 34 35 36 37 38 39
  type PageList = {
    id : string
    name : string
    open : boolean
    pages : PageItem[]
    url ?: string
    enable ?: boolean
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
40

41 42 43 44
  export default {
    data() {
      return {
        list: [
DCloud-WZF's avatar
DCloud-WZF 已提交
45 46 47 48 49 50 51 52 53 54
          {
            id: 'app-instance',
            name: 'App 实例',
            open: false,
            pages: [
              {
                name: 'index',
                url: 'index',
                enable: true,
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
              {
                name: 'globalProperties',
                url: 'globalProperties',
                enable: true,
              },
            ] as PageItem[],
          },
          {
            id: 'built-in-component',
            name: '内置组件',
            open: false,
            pages: [
              {
                name: 'keepAlive',
                url: 'keep-alive',
                enable: true,
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
72 73
            ] as PageItem[],
          },
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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
          {
            id: 'lifecycle',
            name: '生命周期',
            open: false,
            pages: [
              {
                name: 'page',
                url: 'page',
                enable: true,
              },
              {
                name: 'component',
                url: 'component',
                enable: true,
              },
            ] as PageItem[],
          },
          {
            id: 'directive',
            name: '指令',
            open: false,
            pages: [
              {
                name: 'v-for',
                url: 'v-for',
                enable: true,
              },
              {
                name: 'v-for-item-click',
                url: 'v-for/v-for-item-click',
                enable: true,
              },
              {
                name: 'v-for-item-v-if',
                url: 'v-for/v-for-item-v-if',
                enable: true,
              },
              {
                name: 'v-for-item-v-show',
                url: 'v-for/v-for-item-v-show',
                enable: true,
              },
              {
                name: 'v-for-v-for',
                url: 'v-for/v-for-v-for',
                enable: true,
              },
              {
                name: 'v-if',
                url: 'v-if',
                enable: true,
              },
              {
                name: 'v-show',
                url: 'v-show',
                enable: true,
              },
              {
                name: 'v-on',
                url: 'v-on',
                enable: true,
              },
              {
                name: 'v-bind',
                url: 'v-bind',
                enable: true,
              },
              {
                name: 'v-bind-class',
                url: 'v-bind/v-bind-class',
                enable: true,
              },
              {
                name: 'v-bind-style',
                url: 'v-bind/v-bind-style',
                enable: true,
              },
              {
                name: 'v-bind-props',
                url: 'v-bind/v-bind-props',
                enable: true,
              },
              {
                name: 'v-bind-attribute',
                url: 'v-bind/v-bind-attribute',
                enable: false,
              },
              {
                name: 'v-model',
                url: 'v-model',
                enable: true,
              },
              {
                name: 'v-slot',
                url: 'v-slot',
                enable: true,
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
171 172 173 174 175
              {
                name: 'v-html',
                url: 'v-html',
                enable: true,
              },
176 177 178
              {
                name: 'v-pre',
                url: 'v-pre',
DCloud-WZF's avatar
DCloud-WZF 已提交
179
                enable: true,
180 181 182 183
              },
              {
                name: 'v-once',
                url: 'v-once',
雪洛's avatar
雪洛 已提交
184
                // #ifdef APP
DCloud-WZF's avatar
DCloud-WZF 已提交
185
                enable: true,
雪洛's avatar
雪洛 已提交
186 187 188 189
                // #endif
                // #ifdef WEB
                enable: false,
                // #endif
190 191 192 193
              },
              {
                name: 'v-memo',
                url: 'v-memo',
雪洛's avatar
雪洛 已提交
194
                // #ifdef APP
DCloud-WZF's avatar
DCloud-WZF 已提交
195
                enable: true,
雪洛's avatar
雪洛 已提交
196 197 198 199
                // #endif
                // #ifdef WEB
                enable: false,
                // #endif
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
              },
              {
                name: 'v-cloak',
                url: 'v-cloak',
                enable: false,
              },
            ] as PageItem[],
          },
          {
            id: 'state',
            name: '状态',
            open: false,
            pages: [
              {
                name: 'data',
                url: 'data',
                enable: true,
              },
              {
                name: 'props',
                url: 'props',
                enable: true,
              },
              {
                name: 'computed',
                url: 'computed',
                enable: true,
              },
              {
                name: 'methods',
                url: 'methods',
                enable: true,
              },
              {
                name: 'watch',
                url: 'watch',
                enable: true,
              },
            ] as PageItem[],
          },
          {
            id: 'rendering',
            name: '渲染选项',
            open: false,
            pages: [
              {
                name: 'template',
                url: 'template',
                enable: true,
              },
              {
                name: 'render',
                url: 'render',
雪洛's avatar
雪洛 已提交
253
                // #ifdef APP
DCloud-WZF's avatar
DCloud-WZF 已提交
254
                enable: true,
雪洛's avatar
雪洛 已提交
255 256 257 258
                // #endif
                // #ifdef WEB
                enable: false,
                // #endif
259
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
260 261 262 263 264 265 266 267 268 269
              {
                name: 'slots',
                url: 'slots',
                enable: true,
              },
              {
                name: 'component',
                url: 'component',
                enable: true,
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
270 271 272 273
              {
                name: 'unrecognized component',
                url: 'unrecognized-component',
                enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
274
              },
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
            ] as PageItem[],
          },
          {
            id: 'component-instance',
            name: '组件实例',
            open: false,
            pages: [
              {
                name: '$data',
                url: 'data',
                enable: true,
              },
              {
                name: '$props',
                url: 'props',
                enable: true,
              },
              {
                name: '$el',
                url: 'el',
                enable: true,
              },
              {
                name: '$options',
                url: 'options',
                enable: true,
              },
              {
                name: '$parent',
                url: 'parent',
雪洛's avatar
雪洛 已提交
305
                // #ifdef APP
306
                enable: true,
雪洛's avatar
雪洛 已提交
307 308 309 310
                // #endif
                // #ifdef WEB
                enable: false,
                // #endif
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
              },
              {
                name: '$root',
                url: 'root',
                enable: true,
              },
              {
                name: '$slots',
                url: 'slots',
                enable: true,
              },
              {
                name: '$refs',
                url: 'refs',
                enable: true,
              },
              {
                name: '$attrs',
                url: 'attrs',
                enable: true,
              },
              {
                name: '$watch',
                url: 'watch-function',
                enable: true,
              },
337 338 339 340 341
              {
                name: 'watch-array',
                url: 'watch-function/watch-array',
                enable: true,
              },
342 343 344 345 346
              {
                name: '$emit',
                url: 'emit-function',
                enable: true,
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
347 348 349 350
              {
                name: '$forceUpdate',
                url: 'force-update',
                enable: true,
351 352 353 354 355 356
              },
              {
                name: '$nextTick',
                url: 'nextTick-function',
                enable: true,
              },
H
hdx 已提交
357
              {
H
hdx 已提交
358 359
                name: 'call-method-uni-element',
                url: 'methods/call-method-uni-element',
H
hdx 已提交
360 361 362
                enable: true,
              },
              {
H
hdx 已提交
363 364
                name: 'call-method-easycom',
                url: 'methods/call-method-easycom',
H
hdx 已提交
365 366 367
                enable: true,
              },
              {
H
hdx 已提交
368 369 370 371 372 373 374
                name: 'call-method-easycom-uni-modules',
                url: 'methods/call-method-easycom-uni-modules',
                enable: true,
              },
              {
                name: 'call-method-other',
                url: 'methods/call-method-other',
H
hdx 已提交
375 376
                enable: true,
              },
377 378 379 380 381
              {
                name: 'circular-reference',
                url: 'circular-reference',
                enable: true,
              },
382 383 384 385 386 387 388 389 390 391
            ] as PageItem[],
          },
          {
            id: 'composition',
            name: '组合选项',
            open: false,
            pages: [
              {
                name: 'provide',
                url: 'provide',
DCloud-WZF's avatar
DCloud-WZF 已提交
392
                enable: true,
393 394 395 396
              },
              {
                name: 'inject',
                url: 'inject',
DCloud-WZF's avatar
DCloud-WZF 已提交
397
                enable: true,
398 399 400 401
              },
              {
                name: 'mixins',
                url: 'mixins',
雪洛's avatar
雪洛 已提交
402
                // #ifdef APP
DCloud-WZF's avatar
DCloud-WZF 已提交
403
                enable: true,
雪洛's avatar
雪洛 已提交
404 405 406 407
                // #endif
                // #ifdef WEB
                enable: false,
                // #endif
408
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
409 410 411 412 413
              {
                name: 'extends',
                url: 'extends',
                enable: false,
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
414 415 416 417 418
              {
                name: 'setup',
                url: 'setup',
                enable: true,
              }
419 420 421 422 423 424 425 426 427 428 429
            ] as PageItem[],
          },
          {
            id: 'examples',
            name: '示例',
            open: false,
            pages: [
              {
                name: '嵌套组件通信',
                url: 'nested-component-communication',
                enable: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
430
              }, {
431 432 433
                name: '自定义组件中使用 class 定制另一个自定义组件根节点样式',
                url: 'set-custom-child-component-root-node-class',
                enable: true,
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
              }
            ] as PageItem[],
          },
        ] as PageList[],
      }
    },
    methods: {
      goDetailPage(id : string, e : PageItem) {
        if (e.enable == false) {
          uni.showToast({
            icon: 'none',
            title: '暂不支持',
          })
          return
        }
DCloud-WZF's avatar
DCloud-WZF 已提交
449

450 451 452 453 454 455 456 457 458
        const url = e.url!.includes('/') ? e.url : `${e.url}/${e.url}`
        uni.navigateTo({
          url: `/pages/${id}/${url}`,
        })
      },
      // 自动化测试
      setLifeCycleNum(num : number) {
        setLifeCycleNum(num)
      },
459 460 461 462
      // 自动化测试
      getLifeCycleNum() : number {
        return state.lifeCycleNum
      },
463 464 465 466 467
      // 自动化测试
      checkLaunchPath() : boolean {
        const app = getApp()
        return app.checkLaunchPath()
      },
468 469
    },
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
470 471 472
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
473 474 475 476
  .item {
    margin-bottom: 12px;
  }
</style>