首页 > 其他分享 >使用Vue实现点击事件变颜色并且显示选中文字

使用Vue实现点击事件变颜色并且显示选中文字

时间:2023-04-25 14:56:20浏览次数:43  
标签:index Vue color number item 点击 选中 se

首先需要引入Vue.js!!!!!      直接上代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../static/vue.js"></script>
    <style>
        ul{
            background-color: aqua;
        }
 
        .zg{
            background-color: magenta;
        }
    </style>
 
</head>
<body>
 
<div align="center" id="chd">
    <ul v-for="(item,index) in aaa" @click="bbb(item,index)" v-bind:class="{zg:number === index}">
        <li>{{index}}&nbsp;&nbsp;{{item}}</li>
    </ul>
<hr>
<h3>选择了:{{se}}</h3>
    <script>
        var  aaa= new Vue({
            el:"#chd",
            data:{
                aaa:['蔡徐坤','陈厚德','小熊','大熊'],
                se:"",
                number:0
            },
            methods:{
                bbb:function (item,index){
                    this.se=item;
                    this.number=index;
                }
            }
        })
    </script>
</div>
</body>
</html>



效果如如上面展示


标签:index,Vue,color,number,item,点击,选中,se
From: https://www.cnblogs.com/Chenhoude/p/17352584.html

相关文章

  • 老杜2023最新Vue实战精讲(二)Vue核心技术
    动力节点老杜全新版Vue教程笔记分享给大家学习の地止:https://www.bilibili.com/video/BV17h41137i4视频教程从Vue2开始讲解,一步一个案例,知识点由浅入深,然后很自然的过度到Vue3版本。Vue3是目前企业中使用最多的一个版本。视频中会把每一个Vue的知识点讲解的非常通透,不但举例......
  • vue3 拖拽操作学习
    AS-Editor组件git:https://gitee.com/was666/as-editor/tree/vue3.x/体验:http://was666.gitee.io/as-editor/#/home......
  • 使用Qt Designer生成的两个UI文件,实现在主界面中点击后弹出另一个界面
    QtDesigner生成的ui代码policy.py#Formimplementationgeneratedfromreadinguifile'policy.ui'##Createdby:PyQt6UIcodegenerator6.4.2##WARNING:Anymanualchangesmadetothisfilewillbelostwhenpyuic6is#runagain.Donotedit......
  • EAS_字啊listUICTEX中获取选中的id
    @OverridepublicvoidactionInTransfer_actionPerformed(ActionEvente)/**/throwsException/**/{ArrayListidList=getSelectedIdValues();SelectorItemCollectionsic=newSelectorItemCollection();......
  • vue3中如何引入element-icon并使用
    简单来说,步骤就是:安装——注册——按需引入——使用安装#NPM$npminstall@element-plus/icons-vue#Yarn$yarnadd@element-plus/icons-vue#pnpm$pnpminstall@element-plus/icons-vue注册您需要从@element-plus/icons-vue中导入所有图标并进行全局注册。......
  • Nginx配置vue项目模版
    1、hash模式时(#),nginx配置方法location~^/test/cms-h5/{rewrite^/test/cms-h5(.*)$$1break;root/opt/nginx/web/cms-h5/dist;}2、hisotry模式时,nginx配置方法location~^/test/cms-h5/{try_files$uri@cms-h5;}location@cms......
  • Vue2项目实战尚品汇 项目的路由分析
    视频5)路由的配置vue-router路由分为KVnode平台(并非语言)对于后台而言:K即为URL地址V即为相应的中间件http://localhost:8080/0607app.get("/0607",(res,req)=>{res.send('我是祖国的老花骨朵');});前端路由:K即为URL(网络资源定位符)V即为相应的路由组件5.1路由的一......
  • vue3-sign 手写签名组件
    一个简易签名组件,基于vue3和canvas。#安装npmi@sangtian152/vue3-sign-S#oryarnadd@sangtian152/vue3-sign引入在main.js中写入以下内容:import{createApp}from'vue'importvue3Signfrom'@sangtian152/vue3-sign';import"@sangtian152/vue3-s......
  • vue3+jointjs 使用模板添加元素
    关于如何在Vue3和JointJS中使用拖拽模板来创建节点元素,可以按照以下步骤进行:1.安装JointJS使用npm进行安装:```npminstalljointjs```2.在Vue3中创建JointJS容器在Vue3中创建一个组件,用于创建JointJS的画布和节点。在组件的生命周期方法`mounted`......
  • 前端vue使用jsencrypt进行RAS加密/解密
    前端安装:npminstalljencrypt--sava在utils下创建jsencrypt.js文件,内容如下:importJSEncryptfrom"jsencrypt/bin/jsencrypt.min";/**RSA秘钥对生成网站http://web.chacuo.net/netrsakeypair*//**公钥512位*/constpublicKey='MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJ......