我正在尝试在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时,我该怎么做才能滚动到一个元素?
我想使用 rgb(redComp, greenComp, blueComp) 格式设置类的 CSS 属性。我想从 Vuejs 组件代码中获取这些组件。
.progress {
color: rgb(256,0,0);
border-radius: 0px;
}
Run Code Online (Sandbox Code Playgroud)
我希望 CSS 类似于:-
.progress {
color: rgb(redComp, greenComp, blueComp);
border-radius: 0px;
}
Run Code Online (Sandbox Code Playgroud)
其中 redComp、greenComp 和 blueComp 将是 VueJS 组件中的变量。我该如何实施?