簡體   English   中英

ion-content 方法 scrollToPoint 不適用於 Ionic 5

[英]ion-content method scrollToPoint not working on Ionic 5

我正在關注這個ionic5github文檔,以便以編程方式將我的頁面滾動到一個點。 以下是代碼

getContent() {
      return document.querySelector('ion-content');
}

scrollPage() {
      this.getContent().scrollToPoint(100,100);
}

方法scrollToPoint()沒有做任何事情。 還有另一種調用此方法的方法嗎?

您不能在選擇器獲得的項目上應用方法。 你必須是 select 這個 ion-content 帶有@ViewChild並且可以使用方法:

@ViewChild(IonContent) content: IonContent;

content.scrollToPoint(100,100);

如果有人在使用VueJS + Ionic 6時遇到問題。 我通過將 $ref 存儲在 mounted() 上的 data() 中使其工作。 不要忘記像這樣添加 ref 屬性: <ion-content ref="myContent">

data() {
  return {
    myCustomContent: null
  };
}

在你的 mounted()

mounted() {
  this.myCustomContent = this.$refs.myContent.$el;
}

你的方法:

scrollFunction() {
  this.myCustomContent.scrollToBottom(500);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM