doubleyong
管理员
管理员
  • 最后登录2025-02-06
  • 发帖数1196
  • 最爱沙发
  • 喜欢达人
  • 原创写手
  • 社区居民
  • 忠实会员
阅读:2955回复:0

[前端]【uniapp】uniapp中使用vue3获取文本框内容的方法

楼主#
更多 发布于:2022-07-21 15:30
分享:
         uniapp中获取input框中的value值的方法,
        使用v-model 与 ref 结合实现




代码如下:
template

<template>
    <view class="content">
        <view>
            <input v-model="comment" class="uni-input" focus placeholder="自动获得焦点" />
            <view @click="AddComment">评论</view>
        </view>
    </view>
</template>

script代码:
<script>
    import {
        ref,
        getCurrentInstance,
        onMounted,
    } from 'vue'
    export default {
        setup() {
            const comment = ref(null);
            const {
                proxy , ctx
            } = getCurrentInstance();
            onMounted(() => {
                console.log(comment.value);
            })
                   const AddComment = ()=>{
               console.log("评论:",comment.value);
           }
            return {
                comment,
                AddComment
            }
        }
    }
</script>
知识需要管理,知识需要分享
游客


返回顶部

公众号

公众号