WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2021-03-26 02725eb3c7fefa44a4ff2df9807744def27420fa
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
/**
 * CTextArea
 * @author Tevin
 */
 
<template>
    <view class="c-textarea">
        <AtInput
            ref="input"
            :name="itemRes.name"
            :title="itemRes.label"
            :required="itemRes.required"
            :error="itemRes.error"
        />
        <textarea
            ref="textarea"
            class="textarea"
            :style="{height: areaHeight}"
            :placeholder="placeholder"
            :value="itemRes.formData[itemRes.name]"
            :autoFocus="true"
            @input="evt=>itemRes.onChange(evt.detail.value)"
        />
    </view>
</template>
 
<script>
import Taro from '@tarojs/taro';
import { $ } from '@tarojs/extend';
import { AtInput } from 'taro-ui-vue';
import './cTextArea.scss';
 
export default {
    name: 'CTextArea',
    components: {
        AtInput,
    },
    props: {
        height: {
            type: Number,
            default: 94,
        },
        placeholder: String,
        itemRes: Object,
    },
    data() {
        return {};
    },
    computed: {
        areaHeight() {
            return Taro.pxTransform(this.height);
        },
    },
    methods: {},
    mounted() {
        if (process.env.TARO_ENV === 'h5') {
            $(this.$refs.input.$el)
                .find('.at-input__input')
                .prepend(this.$refs.textarea.$el);
        } else if (process.env.TARO_ENV === 'weapp') {
            console.log(this.$refs);
            $(this.$refs.input.$el)
                .find('.at-input__container')
                .append(this.$refs.textarea);
        }
    },
};
</script>