我有一个(单例)服务,该服务在构造函数中包含一些代码,应在启动后直接运行。加载应用程序后,必须立即创建该实例。
实例化服务的一种可能性是将其放入应用程序组件的构造函数中:
export class AppComponent {
constructor(private mySercive: MyService
...
Run Code Online (Sandbox Code Playgroud)
但由于我从未在此组件中使用myService,因此我会收到类似的警告,mySerive is not used并且团队中的其他人可能会删除该服务。有没有办法实例化应用程序模块内部的服务?
我想重命名由index.html生成的npm run build。我在webpack配置中找不到任何内容。
我还在vue.config.js这里创建了一个描述:https : //github.com/vuejs/vue-cli/tree/dev/docs/config
module.exports = {
pages: {
index: {
filename: 'dapp.html',
}
}
};
Run Code Online (Sandbox Code Playgroud)
但是输出文件仍然 index.html
这个异常在 lins 中抛出myList = results['users'];。我也试过了myList = results['users'] as List<String>;。的类型results['users']是List<dynamic>。实际上它包含字符串,为什么不能转换呢?
List<String> myList = List<String>();
results = await ApiService.searchUser();
setState(() {
myList = results['users'];
}
Run Code Online (Sandbox Code Playgroud) 当使用以下代码时,我期望得到一个圆形头像图像,但得到一个椭圆形。我尝试了不同的参数,例如容器的宽度和高度,但这没有帮助。
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: new Icon(Icons.star_border, color: Colors.black),
onPressed: () => {},
),
actions: <Widget>[
Container(
//height: 25.0,
// width: 25.0,
child: CircleAvatar(
backgroundImage: NetworkImage('https://lh3.googleusercontent.com/a-/AAuE7mChgTiAe-N8ibcM3fB_qvGdl2vQ9jvjYv0iOOjB=s96-c'),
)
/*
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
'https://lh3.googleusercontent.com/a-/AAuE7mChgTiAe-N8ibcM3fB_qvGdl2vQ9jvjYv0iOOjB=s96-c')),
),*/
),
],
Run Code Online (Sandbox Code Playgroud) void main() {
MainStream.init();
runApp(
MultiProvider(
providers: [
Provider(
create: (context) => Test(context),
),
],
child: MyApp()));
}
class Test {
Test(BuildContext context) {
print("Test");
}
}
Run Code Online (Sandbox Code Playgroud)
在这个测试代码中,我希望在我的应用程序启动时打印出“Test”,但它没有。我做错了什么?我看到了像这样初始化提供程序的示例。