nativescript-toasty:需要 1 个参数,但得到了 3.ts(2554)
nativescript-toasty: Expected 1 arguments, but got 3.ts(2554)
我正在学习一个教程,它在部分代码中使用了这个功能:
addToFavorites() {
if (!this.favorite) {
console.log('Adding to Favorites', this.dish.id);
this.favorite = this.favoriteservice.addFavorite(this.dish.id);
const toast = new Toasty("Added Dish "+ this.dish.id, "short", "bottom");
toast.show();
}
}
但是由于这行代码 const toast = new Toasty("Added Dish "+ this.dish.id, "short", "bottom");
:
我收到了这条错误消息
Expected 1 arguments, but got 3.ts(2554)
Toasty
class/interface 似乎已更改,但我不知道如何编辑我的代码以获得相同的功能?
Toasty 需要 1 个参数,如下所示:
const toast = new Toasty({ text: 'Toast message' })
您需要使用:
位置:ToastPosition
和持续时间:ToastDuration
示例:
const toasty = new Toasty({
text: 'Somethign something...',
position: ToastPosition.TOP,
duration: ToastDuration.SHORT
});
完整描述:
从'nativescript-toasty'导入{Toasty};
// Toasty 接受一个对象来定制它的 behavior/appearance。唯一需要的值是 text
,这是吐司的消息。
const toast = new Toasty({ text: 'Toast message' });
toast.show();
// 您也可以将这些方法链接在一起,并且不需要使用这种方法创建对 Toasty 实例的引用
new Toasty({ text: 'Some Message' })
.setToastDuration(ToastDuration.LONG)
.setToastPosition(ToastPosition.BOTTOM)
.setTextColor(new Color('white'))
.setBackgroundColor('#ff9999')
.show();
// 或者你可以设置 Toasty 实例的属性
const toasty = new Toasty({
text: 'Somethign something...',
position: ToastPosition.TOP,
android: { yAxisOffset: 100 },
ios: {
anchorView: someButton.ios, // must be the native iOS view instance (button, page, action bar, tabbar, etc.)
displayShadow: true,
shadowColor: '#fff000',
cornerRadius: 24
}
});
toasty.duration = ToastDuration.SHORT;
toasty.textColor = '#fff';
toasty.backgroundColor = new Color('purple');
toasty.show();
构造函数于 18/06/2019 更改为“2.0.0 重构”来自:
constructor(
text: string,
duration?: ToastDuration,
position?: ToastPosition,
textColor?: Color | string,
backgroundColor?: Color | string
)
至
constructor(opts?: ToastyOptions)
我正在学习一个教程,它在部分代码中使用了这个功能:
addToFavorites() {
if (!this.favorite) {
console.log('Adding to Favorites', this.dish.id);
this.favorite = this.favoriteservice.addFavorite(this.dish.id);
const toast = new Toasty("Added Dish "+ this.dish.id, "short", "bottom");
toast.show();
}
}
但是由于这行代码 const toast = new Toasty("Added Dish "+ this.dish.id, "short", "bottom");
:
Expected 1 arguments, but got 3.ts(2554)
Toasty
class/interface 似乎已更改,但我不知道如何编辑我的代码以获得相同的功能?
Toasty 需要 1 个参数,如下所示: const toast = new Toasty({ text: 'Toast message' }) 您需要使用: 位置:ToastPosition 和持续时间:ToastDuration
示例:
const toasty = new Toasty({
text: 'Somethign something...',
position: ToastPosition.TOP,
duration: ToastDuration.SHORT
});
完整描述:
从'nativescript-toasty'导入{Toasty};
// Toasty 接受一个对象来定制它的 behavior/appearance。唯一需要的值是 text
,这是吐司的消息。
const toast = new Toasty({ text: 'Toast message' });
toast.show();
// 您也可以将这些方法链接在一起,并且不需要使用这种方法创建对 Toasty 实例的引用
new Toasty({ text: 'Some Message' })
.setToastDuration(ToastDuration.LONG)
.setToastPosition(ToastPosition.BOTTOM)
.setTextColor(new Color('white'))
.setBackgroundColor('#ff9999')
.show();
// 或者你可以设置 Toasty 实例的属性
const toasty = new Toasty({
text: 'Somethign something...',
position: ToastPosition.TOP,
android: { yAxisOffset: 100 },
ios: {
anchorView: someButton.ios, // must be the native iOS view instance (button, page, action bar, tabbar, etc.)
displayShadow: true,
shadowColor: '#fff000',
cornerRadius: 24
}
});
toasty.duration = ToastDuration.SHORT;
toasty.textColor = '#fff';
toasty.backgroundColor = new Color('purple');
toasty.show();
构造函数于 18/06/2019 更改为“2.0.0 重构”来自:
constructor(
text: string,
duration?: ToastDuration,
position?: ToastPosition,
textColor?: Color | string,
backgroundColor?: Color | string
)
至
constructor(opts?: ToastyOptions)