我想在菜单栏中显示一些数据,需要远程获取(http get call)才能正确显示。当我的应用程序加载时,商店尚未初始化。我应该在哪里做?
这就是我现在所拥有的。nodeInfo是一个空对象,只要没有获取数据。
导航组件
<template>
<nav class="navbar" role="navigation" aria-label="main navigation">
...
<div class="navbar-end">
<span class="navbar-item">
<div v-if="nodeInfo.latestSolidSubtangleMilestoneIndex">
{{nodeInfo.latestSolidSubtangleMilestoneIndex}} / {{nodeInfo.latestMilestoneIndex}}
</div>
<div v-else>
Node seems offline!
</div>
</span>
</div>
</div>
</nav>
</template>
<script>
import {mapGetters} from 'vuex';
export default {
name: 'Menu',
computed: {
...mapGetters(['nodeInfo']) // Only the getters, no actions called to initialize them.
}
};
</script>
<style scoped>
</style>
Run Code Online (Sandbox Code Playgroud)
店铺:
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
import axios from 'axios';
const iri_ip …Run Code Online (Sandbox Code Playgroud) 而不是在我的JUnit测试中进行异常处理,我只是声明我的测试方法... throws Exception?
我开始这样做,我没有看到为什么我应该更具体的原因.
这是一些代码片段。同样的模式 (afaik) 适用于英雄教程。
登录.component.html:
<div class="four wide column middle aligned" *ngIf="wrongCredentialsInserted">
<div class="ui error message">Invalid credentials
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
登录.component.ts:
wrongCredentialsInserted: boolean = false;
//...
onSubmit(login: LoginDto): void {
console.log(`User '${login.username}' attempts to login...`);
if (this.authService.login(login.username, login.password)) {
this.location.back();
} else {
this.wrongCredentialsInserted = true; //This line gets executed!
}
}
Run Code Online (Sandbox Code Playgroud)
即使我设置wrongCredentialsInserted为 true ,该消息也不会显示。它被设置为 true,我已经验证过了。我也尝试过类似的东西*ngIf="wrongCredentialsInserted === true",因为我在其他地方读到过,但是没有用。我读到这可能与“单向数据流,从 Angular 2 开始”有关,但我知道我们能够在我们公司的 A2+ 项目中做这样的事情。AFAIK 一种方式数据绑定仅指组件-组件通信。
任何形式的帮助都受到高度赞赏。
编辑:由于我所做的事情似乎有点混乱,我将整个文件发布在这里。
登录.component.ts
import {AbstractControl, FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {routerTransition} …Run Code Online (Sandbox Code Playgroud) 使用CSS-Grid,我尝试将项目放在网格单元的中心,而不是将它们完全缩小到仅内容。这可能吗?
我在stackblitz上做了一个简单的例子。您会看到那里的项目没有用背景色填充整个网格单元。使该功能正常工作的正确方法是什么?我可以删除justify-items / align-items类,但是内容不再居中。
https://stackblitz.com/edit/angular-8bggtq?file=app/app.component.html
单元格已填充,但内容不在中心:
单元格未填充,但内容居中:
.wrapper {
display: grid;
height: 100vh;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
justify-items: center;
align-items: center;
}
.item {
//justify-self: stretch;
//align-self: stretch;
}
.one {
background: red;
}
.two {
background: pink;
}
.three {
background: violet;
}
.four {
background: yellow;
}
.five {
background: brown;
}
.six {
background: green;
}
html,
body {
margin: 0;
}Run Code Online (Sandbox Code Playgroud)
<div class="wrapper">
<div class="item one">1</div>
<div class="item two">2</div>
<div class="item three">3</div>
<div …Run Code Online (Sandbox Code Playgroud)谁能告诉我为什么我不能在 lit-html 的html方法中使用变量?
const h1 = 'h1';
return html`
<${h1} class="a-heading ${classes}">
<slot></slot>
</${h1}>
`;
Run Code Online (Sandbox Code Playgroud)
如果我替换${h1}为h1没有问题的作品。
javascript web-component custom-element lit-element lit-html
我阅读了很多关于这个主题的内容,而 safari 似乎对此有问题(甚至是 filesaver.js)。我仍然想知道,你们中是否有人有一种方法可以让用户单击按钮并将 json 文件(带有文件名)下载到他的设备。
那里有很多线程,safari 似乎在过去遇到过问题,已经解决了。但目前的 safari 版本似乎仍然无法做到这一点。我把最后的希望寄托在你们身上。更新到最新版本的 iOS 没有帮助。
这是我的方法,适用于 Safari 桌面:
exportButton.addEventListener("click", () => {
const appState = databaseConnector.getApplicationStateAsString();
const blob = new Blob([appState], { type: "text/json" });
const fileName = `backup_${
new Date().toISOString().split("T")[0]
}.json`;
const tempElement = document.createElement("a");
const url = URL.createObjectURL(blob);
tempElement.href = url;
tempElement.download = fileName;
document.body.appendChild(tempElement);
tempElement.click();
setTimeout(function () {
document.body.removeChild(tempElement);
window.URL.revokeObjectURL(url);
});
});
Run Code Online (Sandbox Code Playgroud) 我从未看过一个教程或一些讲座,这些讲座显示了一个经典的for-loop,而不是后增量顺序.
for (int i=0; i<array.length; i++) {}
Run Code Online (Sandbox Code Playgroud)
如果使用POST增量,变量"i"将被缓存,然后才会增加!但这没有任何意义,因为命令直接结束.
在我看来,这更有意义:
for (int i=0; i<array.length; ++i) {}
Run Code Online (Sandbox Code Playgroud)
如果你到现在才明白,我会更进一步(为我的英语而烦恼):
在第一个循环中:
在第二个循环中:
所以第二个循环的性能更高,没有质量损失.还有其他意见吗?
我为我的 git 页面写了一个 readme.md 文件。现在我想在一些论坛上为我的程序做广告。我不想总是更新每一个论坛条目,所以我虽然我只是链接到我的 git repo,他们人们可以通过阅读自述文件来获取有关我的工具的信息(将来,我只需要更新这个单个文件)。
但是,源文件放在顶部,99% 的访问我的存储库的人对代码一无所知。因此,如果他们只看到 readme.md 而不是代码,它会更吸引人们(这可能会吓跑他们“哦,我不明白它看起来很难快速离开”)。
有没有办法用 readme.md 部分切换代码部分?
我有一个npm包,其结构如下:
./
./backend
./package.json
package.json
Run Code Online (Sandbox Code Playgroud)
所以基本上两个npm模块在同一个文件夹中,一个是另一个的子文件,文件结构明智.
我安装的方式是,我将一个安装后的脚本放在父package.json中:
"postinstall": "cd backend && npm install && cd .."
Run Code Online (Sandbox Code Playgroud)
如果我全局安装它会发生什么:它首先打印一些警告,基本上没有安装包.像这样:
npm WARN enoent ENOENT: no such file or directory, open '/usr/lib/node_modules/inschpektor/backend/node_modules/trim-newlines/package.json'
Run Code Online (Sandbox Code Playgroud)
那些出现在所有依赖关系中./backend/package.json.
我已经使用--unsafe-perm标志运行安装:
npm install -g inschpektor --unsafe-perm 它安装包含postinstall脚本的父package.json.
我得到的最终日志错误消息是这一个:
npm ERR! path /usr/lib/node_modules/inschpektor/backend/node_modules/ansi-regex/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/usr/lib/node_modules/inschpektor/backend/node_modules/ansi-regex/package.json'
npm ERR! enoent This is related to npm not being able to …Run Code Online (Sandbox Code Playgroud) 我有这个代码将Image插入borderpane的中心:
private static final ImageView iv;
static {
iv = new ImageView(StartPanel.class.getResource("/com/dx57dc/images/6.jpg").toExternalForm());
}
bpi.setCenter(iv);
Run Code Online (Sandbox Code Playgroud)
现在我遇到了这个问题.我将此插入文本作为图像中心的标签.
文字inftx =新文字("基础设施");
我怎么能这样做?
java ×2
javascript ×2
angular ×1
axios ×1
css ×1
css-grid ×1
css3 ×1
filesaver.js ×1
github ×1
html ×1
increment ×1
ios ×1
javafx ×1
javafx-2 ×1
javafx-8 ×1
junit ×1
junit4 ×1
layout ×1
lit-element ×1
lit-html ×1
node-modules ×1
node.js ×1
npm ×1
npm-install ×1
npm-scripts ×1
safari ×1
unit-testing ×1
vue.js ×1
vuejs2 ×1
vuex ×1