我想计算 IonContent 的当前滚动百分比(它是一个 Ionic + React 应用程序)
页面布局如下所示:
<IonPage>
<IonHeader>
<IonToolbar>
<IonButtons slot="start">
<IonMenuButton />
</IonButtons>
<IonTitle>Page</IonTitle>
</IonToolbar>
</IonHeader>
<IonContentid="main-content"
scrollEvents={true}
onIonScroll={(ev) => {
// ToDo: calculate scroll percentage
console.log(ev.detail.scrollTop);
}}>
{// very long custom component
}
<IonFooter>
<IonLabel>Footer </IonLabel>
</IonFooter>
</IonContent>
</IonPage>
Run Code Online (Sandbox Code Playgroud)
从 IonScroll 事件中,我可以读出scrollTop,它似乎是当前的滚动位置。
现在我需要获取 IonContent 的最大滚动高度。
相关问题有:
第一个问题中接受的答案似乎提供了最完整的方法,通过选择滚动高度值来获取最大值:
var limit = Math.max( document.body.scrollHeight, document.body.offsetHeight,
document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight );
Run Code Online (Sandbox Code Playgroud)
我还添加了以下内容来扩展它:
document.scrollingElement.scrollHeight
Run Code Online (Sandbox Code Playgroud)
问题:
在我的场景中,这些值的最大值约为 660。但是日志记录输出ev.detail.scrollTop高达680.76.
我已连接调试检查器并尝试从控制台滚动,以查看滚动值在 660 左右时会发生什么。从 660 …
我创建了一个带有表单的 Ionic 应用程序。没什么特别的(代码如下)。在我添加表单并使用表单组和其他东西之前,它工作得很好。当我开始添加表单组和所有连接的东西时,我收到此错误:
\n\n\n\n\ncore.js:6260 错误错误:未捕获(承诺中):错误:NodeInjector:\n NOT_FOUND [ControlContainer] 错误:NodeInjector: NOT_FOUND\n [ControlContainer]\n 位于 getOrCreateInjectable (core.js:5894)\n 模块处。 \xc9\xb5\xc9\xb5directiveInject (core.js:21115)\n 在 NodeInjectorFactory.NgControlStatusGroup_Factory [作为工厂] (forms.js:1073)\n 在 getNodeInjectable (core.js:6025)\n 在 instantiateAllDirectives (core. js:12953)\n 在 createDirectivesInstances (core.js:12169)\n 在 \xc9\xb5\xc9\xb5elementStart (core.js:21298)\n 在 EditPage_Template (template.html:18)\n 在executeTemplate (core) .js:12129)\ n在renderView(core.js:11899)\ n在resolvePromise(zone-evergreen.js:798)\ n在resolvePromise(zone-evergreen.js:750)\ n在zone-evergreen.js :860\n 在 ZoneDelegate.invokeTask (zone-evergreen.js:399)\n 在 Object.onInvokeTask (core.js:41640)\n 在 ZoneDelegate.invokeTask (zone-evergreen.js:398)\n 在区域。 runTask (zone-evergreen.js:167)\n 在rainMicroTaskQueue (zone-evergreen.js:569)
\n
我尝试了在网上找到的东西:\n从文件 app.module.ts 中的 @angular/forms 导入 Forms Module 和 ReactiveFormsModule
\n\n这对我不起作用,并且我不断收到错误。
\n\n我在 SO 上找到并尝试过的链接,但没有成功:
\n\n我的 shell 脚本中有以下命令。
\nionic cordova platform add browser\nRun Code Online (Sandbox Code Playgroud)\n这提示我输入“Y”,如下所示:
\n? Are you sure you want to continue? (Y/n)\nRun Code Online (Sandbox Code Playgroud)\n我希望使其成为非交互式的,因此我尝试使用Yes以下内容通过:
echo Y | ionic cordova platform add browser\n\nYes | ionic cordova platform add browser\n\nionic cordova platform add browser << 'Y'\nRun Code Online (Sandbox Code Playgroud)\n与上述;该命令以非交互方式执行,但接受No而不是Yes如下所示:
[WARN] About to add the browser platform to your app.\n\n The browser Cordova platform is not recommended for production use.\n\n Instead, we recommend using platform detection and …Run Code Online (Sandbox Code Playgroud) 我想向基于 Ionic 的应用程序添加功能,以检查相应的应用程序商店是否有更新版本,如果存在,则提示用户下载一次(不要重复 - 他们应该能够跳过并且不会被打扰)。与Siren类似,但适用于 Ionic 以及 Google Play 和 Apple App Store。我看到对本机应用程序和 AppStore 的类似请求以及对 Play Store 的类似请求,但没有任何特定于 Ionic 的请求。我觉得我可以使用应用程序版本和这些请求中列出的 ajax 调用将其缝合在一起,但必须有其他人已经这样做了,并且拥有现有的 Cordova/Capacitor 插件。此外,可能存在细微差别,即简单的解决方案可能会失败(即ajax调用失败、应用商店更改API、设备不支持更新版本等)。
是否有现有的插件或代码可以实现上述行为?
我正在构建一个 Ionic-Vue 5 移动应用程序,我发现自己导入了很多 vue 组件只是为了将它们使用到我的视图中:
import {
IonPage,
IonHeader,
IonToolbar,
IonTitle,
IonContent,
IonInput,
IonButton,
IonAlert,
IonList,
IonItem,
IonCard,
IonCardContent,
IonCardHeader,
IonCardSubtitle,
IonLabel,
IonSpinner
} from "@ionic/vue";
export default defineComponent({
components: {
IonHeader,
IonToolbar,
IonTitle,
IonContent,
IonPage,
IonInput,
IonButton,
IonAlert,
IonList,
IonItem,
IonCard,
IonCardContent,
IonCardHeader,
IonCardSubtitle,
IonLabel,
IonSpinner
},
Run Code Online (Sandbox Code Playgroud)
我知道从性能的角度来看这可能很有用,但是当列表足够大以证明一点性能损失是合理的以大大简化代码时,有一种方法可以一次导入所有离子组件吗?
我正在开发一个 Android/iOS 应用程序,该应用程序使用 Ionic 和应用内购买 2来允许用户购买按月或按年订阅。然后,使用购买令牌以及到期日期将该订阅与他们的帐户(他们从应用程序注册的帐户)绑定在一起。
我面临的问题是,当用户 A使用手机 A购买订阅时,与手机 A和用户 A关联的 Google/Apple 帐户都与购买关联,因此当用户 A注销而用户 B登录时同一手机上的应用程序,用户 B尚未购买订阅,因此当他们尝试购买时,应用内购买 2 自动将状态设置为“已批准/已拥有”,因为与手机A关联的 Google/Apple 帐户已经购买了该应用程序订阅,这会欺骗应用程序认为用户 B也购买了订阅,因此激活用户 B的订阅。
如何防止多个用户登录应用程序并重复使用与 Google/Apple 帐户关联的订阅?我将非常感谢任何与此相关的提示或技巧。
这可能是一个令人困惑的问题,如果是这样的话,我深表歉意。
如果有任何帮助,我将不胜感激。先感谢您!
我正在使用 React 和 Ionic,提交表单后,我想以编程方式导航到下一条路线,
当我做:
const { navigate } = useContext(NavContext);
// After Async call....
navigate("/", "forward", "pop").
Run Code Online (Sandbox Code Playgroud)
有用。
当我在这里查看 ionic-react 文档时: https: //ionicframework.com/docs/react/navigation#navigation我看到他们曾经history以编程方式导航,并且它说note: history is a prop.
我尝试了上面的语句,我得到:Property 'history' does not exist on type '{ children?: ReactNode; }'.
需要一个解释。
应用程序.tsx
<IonRouterOutlet>
<Route exact path="/" component={Dashboard} />
<Route path="/home" component={Home} exact={true} />
<Route path="/login" component={Login} />
<Route path="/signup" component={Signup} />
</IonRouterOutlet>
Run Code Online (Sandbox Code Playgroud) 我创建了一个带有电容器的新项目离子。我使用离子选择,但我有一个新的离子选择选项,带有大文本,而不是在输入中分布。
\n<ion-item>\n <ion-label class="my-label" position="stacked">Plaga/Enfermedad</ion-label>\n <ion-select >\n <ion-select-option value="Alternaria, Mancha marr\xc3\xb3n de las mandarinas (primavera)">Alternaria, Mancha marr\xc3\xb3n de las mandarinas (primavera)\n </ion-select-option>\n\n </ion-select>\n</ion-item>\nRun Code Online (Sandbox Code Playgroud)\n如何更改此属性以查看所有文本。\n显示我的图像
\n\n我想将 ionic 中的元素水平居中,左右边距相同
<div class="tabs-group" class="ion-justify-content-center">
<ion-row>
<ion-col *ngFor="let i of tabsName,let j = index" size="4" (click)="switchToTabs(tabsindicator[j])" [ngClass]="tabs[tabsindicator[j]] ? 'primary-button' : 'secondary-button'">
<ion-grid>
<ion-row>
</ion-row>
<ion-row>
<ion-col>
<b>{{tabsName[j]}} </b>
</ion-col>
</ion-row>
</ion-grid>
</ion-col>
</ion-row>
</div>Run Code Online (Sandbox Code Playgroud)
ion-justify-content-center ionic CSS 类没有应用居中,这是输出:
尝试在我的离子应用程序中使用存储版本 2.1.3 但出现错误:
NullInjectorError: R3InjectorError(AppModule)[AppModule -> Storage -> Storage -> Storage]: NullInjectorError: No provider for Storage! ionic 6
Run Code Online (Sandbox Code Playgroud)
我看到一些关于它的帖子,告诉我们使用 forRoot 语句,但无论如何都不起作用。
我的应用程序模块:
import { NgModule, OnInit } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { IonicStorageModule } from '@ionic/storage'
import {HttpClientModule} from '@angular/common/http'
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, HttpClientModule, IonicModule.forRoot(), IonicStorageModule.forRoot(), …Run Code Online (Sandbox Code Playgroud) ionic-framework ×10
angular ×3
css ×2
html ×2
android ×1
bash ×1
ionic-native ×1
ionic-vue ×1
ios ×1
javascript ×1
react-router ×1
reactjs ×1
shell ×1
vue.js ×1