Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add dir rtl attribute to html tag in vuejs

I created a vue project using vue create command . I want to add attribute dir="rtl" to my html tag. in Nuxt.js we do that:

<template>
    <div>Main View</div>
</template>
<script>
export default {
    name: 'app',
    head: {
        htmlAttrs: {
          lang: 'fa',
          dir: 'rtl'
        },
    }
</script>

but in Vuejs This does not work. how can i do this?

like image 474
Majid Ghafoorzade Avatar asked Oct 21 '25 11:10

Majid Ghafoorzade


1 Answers

Try to put this configuration inside the created hook of Vue instance as follows :

new Vue({
    el:"#app",
     ...

    created(){
       let htmlEl=document.querySelector("html");
        htmlEl.setAttribute('dir','rtl');
        htmlEl.setAttribute('lang','fa');
      }
   })
like image 68
Boussadjra Brahim Avatar answered Oct 23 '25 01:10

Boussadjra Brahim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!