Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll down to element with a class name on Vuejs component

I have a component with unordered list and what I want to do is when component is loaded I want the component to be scrolled down to

  • element with a class name 'actual-month' so it can be visible.
    <b-card no-body header="<i class='fa fa-align-justify'></i> Unorderd List"  style="height: 680px">
              <b-tabs card pills>
                  <b-tab v-for="debt in user_debts"  :title="Debts list"  :key="debt.id" class="card-height">             
                     <table class="table table-sm amortization-header header-fixed">
                      <thead>
                          <tr>
                            <th>Month</th>
                            <th>Balance</th>
                            <th>Paid</th>
                            <th>Debt</th>
                            <th>Nominal Interest</th>
                          </tr>
                      </thead>
                      <tbody> 
                        <tr v-for="month in amortization.schedule" :class="{'actual-month' : month.month == amortization.actual_month}">
                          <td>{{month.month}}</td>
                          <td>{{month.balance.toLocaleString()}}<span class="total">€</span></td>
                          <td>{{month.monthly_payment}}<span class="total">€</span></td>
                          <td>{{month.principle}}<span class="total">€</span></td>
                          <td>{{month.interest}}<span class="total">€</span></td>
                        </tr>
                      </tbody>
                    </table>
                  </b-tab>
              </b-tabs>
            </b-card>
    
  • like image 779
    Bernard Doci Avatar asked Dec 12 '17 09:12

    Bernard Doci


    1 Answers

    You can use scrollIntoView:

    mounted: function (){
      var el = this.$el.getElementsByClassName("actual-month")[0];
      el.scrollIntoView();
    }
    
    like image 142
    Julien Avatar answered Oct 27 '22 00:10

    Julien