vue多选功能

废话不多说,直接上代码!!!

<template>
  <div class="duo-xuan-page">
    <li
      v-for="(item, index) in list"
      :key="index"
      @click="toggleSelection(item)"
      :class="{ active: selectedItems.includes(item) }"
    >
      {{ item.tit }}
    </li>
  </div>
</template>
 
<script>
  export default {
    name: 'duo-xuan',
    data () {
      return {
        list: [
          {
            tit: '点我选择111'
          },
          {
            tit: '点我选择222'
          },
          {
            tit: '点我选择333'
          },
          {
            tit: '点我选择444'
          },
          {
            tit: '点我选择555'
          },
          {
            tit: '点我选择666'
          },
          {
            tit: '点我选择777'
          },
          {
            tit: '点我选择888'
          },
          {
            tit: '点我选择999'
          },
          {
            tit: '点我选择1010'
          }
        ],
        selectedItems: [] // 用于存储已选中项的每一项
      }
    },
    methods: {
      toggleSelection(item) {
        // 检查已选中项数组中是否包含当前点击项
        const selectedIndex = this.selectedItems.indexOf(item);
        if (selectedIndex === -1) {
          // 如果当前项未被选中,则把点击项添加到数组中
          this.selectedItems.push(item);
        } else {
          // 如果当前项已被选中,则从已选中项数组中移除
          this.selectedItems.splice(selectedIndex, 1);
        }
      }
    }
  }
</script>
 
<style lang="scss" scoped>
.duo-xuan-page {
  width: 100vw;
  height: 100vh;
  padding: 0 10px;
  box-sizing: border-box;
  overflow: auto;
  li {
    line-height: 100px;
    text-align: center;
    background-color: #ddd;
    list-style: none;
    margin: 20px 0;
    border-radius: 10px;
    font-size: 18px;
    font-weight: bold;
    &.active {
      border: 3px solid #67c23a;
      position: relative;
      &::before {
        content: '';
        position: absolute;
        top: 0px;
        right: 10px;
        width: 6px;
        height: 12px;
        border-bottom: 3px solid #fff;
        border-right: 3px solid #fff;
        transform: rotate(40deg);
        -webkit-transform-origin: left bottom;
        transform-origin: left bottom;
        z-index: 2;
      }
      &::after {
        content: "";
        position: absolute;
        top: 0px;
        right: 0px;
        width: 0;
        height: 0;
        border-left: 45px solid transparent;
        border-top: 45px solid #67c23a;
        z-index: 1;
      }
    }
  }
}
</style>

效果图

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
如果您想在 Vue 中实现多选后跳转多个路由,可以按照以下步骤进行操作: 1. 首先,确定您使用的是 Vue Router 进行路由管理。如果没有安装 Vue Router,可以通过以下命令进行安装: ``` npm install vue-router ``` 2. 在您的 Vue 项目中创建一个路由文件,比如 `router.js`。在该文件中,导入 VueVue Router,并使用 `Vue.use(VueRouter)` 来启用路由功能。 ```javascript import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) ``` 3. 在 `router.js` 中定义您的路由配置,包括多个路由和对应的组件。 ```javascript import Home from './components/Home.vue' import Page1 from './components/Page1.vue' import Page2 from './components/Page2.vue' const routes = [ { path: '/', component: Home }, { path: '/page1', component: Page1 }, { path: '/page2', component: Page2 } ] const router = new VueRouter({ routes }) ``` 4. 在您的 Vue 组件中,使用 `<router-link>` 组件来实现页面跳转,并通过 `to` 属性指定目标路由的路径。 ```html <template> <div> <ul> <li> <router-link to="/">Home</router-link> </li> <li> <router-link to="/page1">Page 1</router-link> </li> <li> <router-link to="/page2">Page 2</router-link> </li> </ul> </div> </template> ``` 5. 如果您想在多选后跳转多个路由,可以在组件中处理多选的逻辑,并在适当的时候使用 `this.$router.push()` 方法来实现路由跳转。 ```javascript methods: { handleMultiSelect() { // 假设选中的路由路径存储在 selectedRoutes 数组中 const selectedRoutes = ['/page1', '/page2'] // 遍历选中的路由路径,并逐个进行路由跳转 selectedRoutes.forEach(route => { this.$router.push(route) }) } } ``` 通过以上步骤,您可以实现在 Vue多选后跳转多个路由的功能。请根据您的具体需求进行相应的调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值