call-method-uni-element.uvue 744 字节
Newer Older
H
hdx 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<template>
  <view>
    <slider ref="slider1"></slider>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        $slider1: null as UniSliderElement | null
      }
    },
    onReady() {
      // 通过组件 ref 属性获取组件实例, Uni组件名(驼峰)Element
      this.$slider1 = this.$refs['slider1'] as UniSliderElement;
    },
    methods: {
      setValue() : boolean {
        // 设置组件的 value 属性
        this.$slider1!.value = 80;
        return true;
H
hdx 已提交
23 24 25 26 27 28
      },
      callMethodTest(text: string): string | null {
        this.$slider1!.setAttribute('value', text);
        const result = this.$slider1!.getAttribute('value')! as string;
        return result;
      },
H
hdx 已提交
29 30 31
    }
  }
</script>