• DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        How to use refs in vue js as querySelectAll

        122 Views Asked by Diana At 28 March 2022 at 08:15 2025-12-07T10:03:35.400000

        What I need is to change the color of links when scrolling up and down. How can I select Link 1/2/3 by using ref?

        <nav class="header-nav">
           <ul>
             <li class="tablet-sm-hide">
               <router-link to="/">Link 1 </router-link>
             </li>
             <li class="tablet-sm-hide">
               <router-link to="/">Link 2  </router-link>
             </li>
             <li class="tablet-sm-hide">
               <router-link to="/">Link 3 </router-link>
             </li>
               </ul>
        
        </nav>
        
        vue.js vuejs3 refs
        Original Q&A
        2

        There are 2 best solutions below

        1
        GMKHussain GMKHussain On 28 March 2022 at 09:13 BEST ANSWER

        Use this method

        this.$refs["n1"].$el.style.color = 'red'
        this.$refs["n2"].$el.style.color = 'green'
        this.$refs["n3"].$el.style.color = 'blue'
        <nav class="header-nav">
            <ul>
                <li class="nav">
                    <router-link to="/" ref="n1">Link 1 </router-link>
                </li>
                <li class="nav">
                    <router-link to="/" ref="n2">Link 2  </router-link>
                </li>
                <li class="nav">
                    <router-link to="/" ref="n3">Link 3 </router-link>
                </li>
            </ul>
        </nav>

        0
        Maik Lowrey Maik Lowrey On 28 March 2022 at 08:40

        You have access to your refs by using this.$refs.

        example

        const anchors = this.$refs["a"];
        
        console.log(anchors);
        

        Related Questions in VUE.JS

        • Problems with matter.js and i18n in vue.js
        • Form Validation not working in custom component Vue
        • Authenticating vue app on each route change
        • Vue/TailwindCSS - Content is behind Sidebar
        • Vue3 Suspense Parent > Child Animation
        • Pass dynamic object data via nuxt-link to component
        • Failed to resolve import, but the path is valid, and detected as such by VSCode
        • how to use less variables in vue components?
        • Prevent a webpage from navigating away
        • Creating a modal window in product edit page in Shopware6 and saving data to custom table(repository) from a form within the modal window
        • How do I fix (or ignore) a TypeScript error that's inside a HTML template?
        • Vue.js Checkbox Alignment Issue: Centering Checkboxes Within Table Cells
        • How to reset vue product filter?
        • Vue display output of two dimensional array
        • vue js error when adding bonus items to another item

        Related Questions in VUEJS3

        • Problems with matter.js and i18n in vue.js
        • Vue3 Suspense Parent > Child Animation
        • Problem sending HTTP post request from VUE to ASP.NET Core MVC project
        • How to import a local image in vuex store without using axios
        • Vue TransitionGroup not working properly because of css transition
        • tsParticles onHover not working on my Vue Project
        • Vue.js Event Emitted in Child Component Not Detected by Parent Component
        • Resource URI is recognised but page wont load and browser throws 404, route:list says the route exist
        • vue 3 phaser and spine.js - Uncaught TypeError: Cannot read properties of undefined (reading 'data')
        • Inertia/Vue: keep getting props undefined error
        • How to make source dynamic for vue-i18n
        • How do I dynamically handle endless nested routes with Nuxt 3?
        • Vue 3 router changing <routing-view/> but not URL
        • Creating base pinia action that can be mixed-in to several stores with typescript
        • Vue.js - define v-model with defineProps and defineModel

        Related Questions in REFS

        • how to use both ref and v -for in my custom component in Vue 3?
        • Property 'current' does not exist on type 'number | MutableRefObject (when number not set as its type)
        • Win32 filesystem "FILE_SUPPORTS_POSIX_UNLINK_RENAME" - what does it do?
        • dev drive performance for c++
        • overwrite git's history with commits in refs/replace
        • `PermissionError` occurs when use `os.rename()` or `os.replace()` on files of a Windows ReFS drive mounted to WSL2
        • vuejs - why "this.$refs.variable" gives undefined, but when I use the value of the "variable" it works
        • Cannot read properties of undefined (reading '$refs') vue js
        • How to use git's negative refspecs?
        • Vue difference of refs and javascript method like getElementById
        • Using refs and .reduce scroll to the id of selected element with react with useState
        • Obtain value from InputText using React.createRef()
        • Vue dynamically added :ref in v-for are not shown in this.$refs
        • How to use refs in vue js as querySelectAll
        • How to achieve this kind of Operation in Vue JS?

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates