Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

请问 Vue中能不能绑定html元素的scrollTop属性?

直接使用document.getElementById('xx').scrollTop可以查看和修改。现在想在Vue中绑定这个属性 并用methods里控制该属性,下面的写法不行呢。 请问Vue有没有什么办法可以控制 该属性。

<div id='ss' :scrollTop="aa()"></div>
var vm=new Vue({
    el:"#ss",
    data:{},
    methods:{
        aa:function(){
            return 40
        }}
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<div id='ss' :scroll-top.prop="aa()"></div>

用.prop修饰符绑定DOM属性
见:https://cn.vuejs.org/v2/api/#...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...