Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ctf0/vue-multi-ref


https://github.com/ctf0/vue-multi-ref

directive javascript utility vuejs

Last synced: 4 days ago
JSON representation

Awesome Lists containing this project

README

        


Vue Multi Ref


npm npm

This is a directive to help use same `ref` on more than one element.

Big thanx to [@Herteby](https://github.com/herteby) & [@LinusBorg](https://github.com/LinusBorg). :fire::metal::clap:

[original post](https://forum.vuejs.org/t/how-to-use-the-same-ref-for-more-than-one-item/22481).

## Installation

```bash
npm install vue-multi-ref --save
```

## Usage

- register the directive

```js
import Vue from 'vue'
import VueMultiRef from 'vue-multi-ref'

Vue.use(VueMultiRef)
new Vue({ el: '#app' })
```

or using Vue as global variable

```js
window.Vue = require('vue')
require('vue-multi-ref')

new Vue({ el: '#app' })
```

- now add `v-multi-ref:refName` to any number of elements that you want to have the same ref, ex.
+ `refName` could be
- camelCase = `refName`
- kebab-case = `ref-name`
- snake-case = `ref_name`

```html

a

  • b

  • c
    ```

    - result

    ```js
    // console.log(this.$refs['my-ref'])

    > my-ref: (3) [div, li, a]
    ```

    ### Security

    If you discover any security-related issues, please email [[email protected]](mailto:[email protected]).