vue 锚链接

min.js

1 Vue.directive('anchor', { // 锚链接自定义指令
2     inserted: function (el, binding) {
3         el.onclick = function () {
4             document.documentElement.scrollTop = $('#anchor-' + binding.value).offset().top
5         }
6     }
7 });

xxx.vue

1 <template>
2     <div class="modular1" v-anchor="index" v-for="(item,index) in $t('producTmodulArr')" :key="index">
3       <div class="modularImg">
4         <img :src="item.url" alt="" width="108" height="98">
5       </div>
6       <div class="modularText"><p>{{item.text}}</p></div>
7     </div>
8 </template>
原文地址:https://www.cnblogs.com/xiaozhu-zhu/p/11946857.html