• uniapp实现点击标签文本域中显示标签内容


    先上一个效果图

     实现的效果有:

    ①.点击标签时,标签改变颜色并处于可删除状态

    ②.切换标签,文本域中出现标签的内容

    ③.点击标签右上角的删除可删掉标签,同时清除文本域中标签的内容

    ④.可输入内容,切换时不影响输入的内容

    使用的是uniapp+vue3+uVieww-plus

    代码:

    1. <script setup>
    2. import {
    3. reactive,
    4. ref,
    5. toRaw,
    6. onMounted,
    7. watch,
    8. computed
    9. } from 'vue';
    10. import {
    11. onLoad,onReady
    12. } from '@dcloudio/uni-app'
    13. // const textareaValue = ref('')
    14. const radios = ref([
    15. {
    16. checked: true,
    17. show:true,
    18. closable:false,
    19. bgColor: '#ffffff',
    20. color:'rgba(0, 0, 0, 0.90)',
    21. content:'商机对接1'
    22. },
    23. {
    24. checked: false,
    25. show:true,
    26. closable:false,
    27. bgColor: '#ffffff',
    28. color:'rgba(0, 0, 0, 0.90)',
    29. content:'商机对接2'
    30. },
    31. {
    32. checked: false,
    33. show:true,
    34. bgColor: '#ffffff',
    35. color:'rgba(0, 0, 0, 0.90)',
    36. content:'商机对接3'
    37. },
    38. {
    39. checked: false,
    40. show:true,
    41. closable:false,
    42. bgColor: '#ffffff',
    43. color:'rgba(0, 0, 0, 0.90)',
    44. content:'商机对接4'
    45. },
    46. {
    47. checked: false,
    48. show:true,
    49. closable:false,
    50. bgColor: '#ffffff',
    51. color:'rgba(0, 0, 0, 0.90)',
    52. content:'商机对接5'
    53. },
    54. ])
    55. const reason1 = ref('');
    56. const reason2 = ref('');
    57. const textareaValue = computed({
    58. get: () => reason1.value + reason2.value,
    59. set: (value) => {
    60. for (let i = 0; i < radios.value.length; i++) {
    61. if (value.includes(radios.value[i].content)) {
    62. reason1.value = radios.value[i].content;
    63. reason2.value = value.replace(radios.value[i].content, '');
    64. return;
    65. }
    66. }
    67. }
    68. })
    69. const radioClick = (name)=> {
    70. // console.log('radios.value',name)
    71. radios.value.map((item, index) => {
    72. if(index === name){
    73. item.checked = true
    74. item.bgColor = 'rgba(0, 82, 217, 0.70)'
    75. item.color = '#ffffff'
    76. item.closable = true
    77. reason1.value = item.content
    78. }else{
    79. item.checked = false
    80. item.bgColor = '#ffffff'
    81. item.color = 'rgba(0, 0, 0, 0.90)'
    82. item.closable = false
    83. }
    84. })
    85. }
    86. const close = (item)=>{
    87. console.log('关闭')
    88. item.show = false
    89. reason1.value = ''
    90. }
    91. const submit = ()=> {}
    92. script>
    93. <style>
    94. page{
    95. background: #F5F5F5;
    96. }
    97. .u-page__tag-item{
    98. height: auto;
    99. margin:0 20rpx 20rpx 0;
    100. }
    101. .u-page__tag-item text {
    102. display: inline-block;
    103. padding: 18rpx 32rpx;
    104. }
    105. .tjBtn{
    106. background: #0052D9;
    107. color: #fff;
    108. border-radius: 6px;
    109. padding: 24rpx 118rpx;
    110. }
    111. style>

     有些样式在全局定义的,自行设置样式。

  • 相关阅读:
    2022年了还不懂JVM?一文带你深入解析
    【JavaScript面试】map()方法
    应用层 HTTP消息在服务端的路由 请求头 Host
    大数据集群中部署Hive
    第七届 Sky Hackathon 笔记集合贴
    上周热点回顾(2.26-3.3)
    OJ项目——使用JWT生成Token
    ArduPilot开源飞控之AP_ExternalAHRS_VectorNav
    017-$route、$router
    WAL 模式(PostgreSQL 14 Internals翻译版)
  • 原文地址:https://blog.csdn.net/m0_67880202/article/details/136660117