相关疑难解决方法(0)

使用scrollIntoView()的VueJS组件

我正在尝试在vue组件中使用document.getElementById().scrollIntoView()来使用Jump-To-Div类型的功能.

如果我在组件中调用该函数,该功能可以正常工作.但是如果我尝试使用ref从父组件调用该函数,则该元素不会滚动到视图中.

父组件是页面,子组件是页面中的选项卡.

这是父组件中的子Vue组件: -

<el-tab-pane label="Solution Details" name="Solution Details" v-loading="loading">
                <solution-details
                    :formData="response"
                    ref="solutionDetails"
                    @done="$emit('done')">
                </solution-details>
            </el-tab-pane>
Run Code Online (Sandbox Code Playgroud)

所以有一个SolutionDetails.Vue子组件,它有一个ref ="solutionDetails".我使用子组件的ref 在父组件中调用此方法:

handleClick(command) {
            this.activeTab = 'Solution Details';
            this.$refs.solutionDetails.showCurrent(command);
        },
Run Code Online (Sandbox Code Playgroud)

子组件中有一个showCurrent函数,它应该为参数"command"执行.这是子组件中的该函数.

methods: {
        showCurrent(index) {
            document.getElementById(index).scrollIntoView();
        },
Run Code Online (Sandbox Code Playgroud)

如您所见,showCurrent应该获取页面中的元素并应滚动到视图中.如果SolutionDetails.vue是活动选项卡,则相应的元素将完全滚动到视图中.但我正在从其他选项卡执行父函数,然后this.activeTab = 'Solution Details';正在执行,即.活动选项卡正在更改为SolutionDetails.vue,但请求的元素不会滚动到视图中.

当其他标签是activeTab时,我该怎么做才能滚动到一个元素?

html javascript getelementbyid vue.js vue-component

6
推荐指数
2
解决办法
7520
查看次数

单击按钮即可打开Vue.js模式

如何使用按钮显示其他组件中的模态?例如,我具有以下组件:

info.vue

<template>
  <div class="container">
    <button class="btn btn-info" @click="showModal">show modal</button>
    <example-modal></example-modal>
  </div>
</template>

<script>
import exampleModal from './exampleModal.vue'
export default {
  methods: {
    showModal () {
      // how to show the modal
    }
  },
  components:{
    "example-modal":exampleModal
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

exampleModal.vue

<template>
    <!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-body">
            hihi
        </div>
        <div class="modal-footer">
            <button type="button" …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js bootstrap-4 vuejs2

5
推荐指数
2
解决办法
2万
查看次数