我有一个快速 API 端点,我需要从查询参数接收两个数字。
问题是我无法将它们正确地转换为数字类型常量。
我总是收到以下打字稿错误:
Argument of type 'string | ParsedQs | string[] | ParsedQs[]' is not assignable to parameter of type 'string'.
export const getRoutes = async (req: Request, res: Response) => {
const page:number = parseInt(req.query.page)
const limit:number = parseInt(req.query.limit)
Run Code Online (Sandbox Code Playgroud) 我有一个项目,我需要在表单中使用选择。所有其他类型的输入都有一个浅灰色的占位符。输入中输入的文本是黑色的。
表单的选择输入需要具有相同的样式。默认/占位符值需要以深灰色显示,用户可以选择的实际值需要以黑色显示。但是当我尝试为第一个(默认/占位符)选项指定不同的颜色时,它不使用这种颜色。它实际上继续使用选择元素中指定的颜色。
这是元素内的选择:
<select
type="text"
name="carType"
id="carType"
v-model="carType"
placeholder="Car Type"
class="my-2 px-4 py-3 border rounded-lg text-black-primary focus:outline-none text-sm"
>
<option class="text-gray-400" value="" disabled selected>Select your option</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Run Code Online (Sandbox Code Playgroud) 我有一个项目,我必须使用一张桌子。我正在使用材料表。但我似乎无法让它看起来正确。表格所需的图标没有显示,而是我得到了一些占位符文本。
这是我用来显示表格的代码。我在项目中安装了材料表和材料图标。
class RegistrationList extends Component {
state = {
registrations: [],
};
infoButtonHandler(id) {}
componentDidMount() {
axios.get("http://localhost:3030/api/items").then((res) => {
let registrations = [];
res.data.forEach((registration) => {
let childeren = "";
for (let i = 0; i < registration.childeren.length; i++) {
childeren += registration.childeren[i].name;
if (i + 1 !== registration.childeren.length) {
childeren += ", ";
}
}
registrations.push({
_id: registration._id,
name: registration.name,
childeren: childeren,
street: registration.street,
houseNumber: registration.houseNumber,
city: registration.city,
postalCode: registration.postalCode,
});
});
this.setState({ registrations: registrations });
});
} …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用类验证器来验证传入的数据。数据由对象数组组成。每个对象都应该经过验证。
我面临的问题是,当所有内容都正确输入时,我不断收到错误。似乎正在检查父类及其子类的属性,因此whitelistValidation
子类的每个属性都会抛出错误。
这是正在生成的错误:
[
{
"target":{
"drainPoints":[
{
"drainPointType":"roundsurface",
"flowType":"normal",
"flowCoefficient":0.5,
"point":{
"x":0,
"y":0
}
}
]
},
"value":[
{
"drainPointType":"roundsurface",
"flowType":"normal",
"flowCoefficient":0.5,
"point":{
"x":0,
"y":0
}
}
],
"property":"drainPoints",
"children":[
{
"target":[
{
"drainPointType":"roundsurface",
"flowType":"normal",
"flowCoefficient":0.5,
"point":{
"x":0,
"y":0
}
}
],
"value":{
"drainPointType":"roundsurface",
"flowType":"normal",
"flowCoefficient":0.5,
"point":{
"x":0,
"y":0
}
},
"property":"0",
"children":[
{
"target":{
"drainPointType":"roundsurface",
"flowType":"normal",
"flowCoefficient":0.5,
"point":{
"x":0,
"y":0
}
},
"value":"roundsurface",
"property":"drainPointType",
"constraints":{
"whitelistValidation":"property drainPointType should not exist"
}
},
{
"target":{
"drainPointType":"roundsurface",
"flowType":"normal", …
Run Code Online (Sandbox Code Playgroud) 我有一个项目需要在 Vuex 商店内进行翻译。但当我尝试在商店内使用 i18n 进行翻译时,我不断收到错误。
我尝试使用以下导入语句在商店内导入 i18n 实例。但我然后得到一个错误Uncaught TypeError: _i18n__WEBPACK_IMPORTED_MODULE_3__.default.t is not a function
import i18n from '@/i18n';
Run Code Online (Sandbox Code Playgroud)
在我的 Vue 项目的 main.js 文件中,我导入并使用 i18n 文件:
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import { store } from './store';
import i18n from './i18n';
createApp(App).use(i18n).use(store).use(router).mount('#app');
Run Code Online (Sandbox Code Playgroud)
这是我的 i18n.js 文件,位于src
文件夹内:
import { createI18n } from 'vue-i18n';
function loadLocaleMessages() {
const locales = require.context(
'./locales',
true,
/[A-Za-z0-9-_,\s]+\.json$/i
);
const messages = {};
locales.keys().forEach((key) => { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Tailwind 为项目创建一个表单。对于这个项目,我需要创建某种类型的输入字段。当该字段获得焦点时,该字段的占位符应更改输入边框顶部的位置。使用 Tailwind 可以实现这一点吗?
这是我正在使用的输入的代码:
<input
type="text"
name="email"
id="email"
v-model="email"
placeholder="Email address"
class="my-2 px-4 py-2 border rounded-lg text-gray-700 focus:outline-none text-sm"
/>
Run Code Online (Sandbox Code Playgroud)
这是一个如何在聚焦时显示输入的示例:
我有一个 Vue 项目,我尝试在其中绘制一个简单的圆环图。我尝试创建的图表显示在 D3.js 的文档中:Donut Chart。
但是当我尝试在 Vue 中创建它时,我似乎无法让它工作。我不断得到一个
[Vue warn]: Error in mounted hook: "TypeError: _ is not iterable"
.
还有一种方法可以让 SVG 填充父级 div,以便它响应父级的宽度和高度。
<template>
<div class="p-3 flex flex-col">
<div class="w-full flex-1">
<div id="my_dataviz"></div>
</div>
</div>
</template>
<script>
import * as d3 from "d3";
export default {
name: "DoughnutChartItem",
props: {
data: {
type: Array,
required: true
}
},
mounted() {
// set the dimensions and margins of the graph
var width = 450;
var height = …
Run Code Online (Sandbox Code Playgroud) 我有一个项目,尝试创建堆积条形图。其要求之一是图表应该能够更新。我已经使用通用更新模式来完成此任务。但我无法让代码工作。
当图表更新时,新生成的图表从底部进入。所以我猜这意味着代码永远不会执行模式的更新部分,并且始终认为更新的数据是新数据。
我在代码片段中添加了 3 个不同的数据数组,为我面临的问题提供了一个很好的例子。前两个数组包含相同的键,应该更新图表。最后一个数组包含完全不同的键,这里应该输入图表而不是更新。
我还注意到,当新数据添加到图表中时。旧数据永远不会被删除。因此更新模式的退出状态也不会被触发。
我知道更新模式的数据函数中应该定义一个键.data(stackData, d => {return d.key;})
。但我似乎不知道应该输入什么键。
我已从原始代码中删除了所需的尽可能多的代码,以便使其适用于代码片段。需要代码片段中包含的所有代码才能使其正常工作。
this.width = 400;
this.height = 200;
var margin = {
top: 20,
right: 20,
bottom: 30,
left: 40
}
this.index = 0;
this.svg = d3
.select(".canvas")
.classed("svg-container", true)
.append("svg")
.attr("class", "chart")
.attr(
"viewBox",
`0 0 ${this.width} ${this.height}`
)
.attr("preserveAspectRatio", "xMinYMin meet")
.classed("svg-content-responsive", true)
.append("g");
const scale = [0, 1200];
// set the scales
this.xScale = d3
.scaleBand()
.range([0, width])
.padding(0.3);
this.yScale = d3.scaleLinear().range([this.height, 0]);
this.svg.append("g").attr("class", "bars"); …
Run Code Online (Sandbox Code Playgroud)我有一个使用 Vue 3 和 Vuex 的项目。这是我第一次使用 Vue 3。我似乎不知道如何在 Vue 3 项目的 Setup 方法中访问 Vuex。
我有一个特征对象。这是由子组件使用 featureSelected 方法设置的。首先,在我的设置中,我使用 useStore 创建一个存储常量;从 import { useStore } from "vuex";
。然后,在 featureSelected 函数内,我调用此存储对象上的调度函数store.dispatch("setPlot", { geometry: newFeature });
。
我不断收到错误消息,告诉我存储对象上不存在调度函数:Uncaught TypeError: store.dispatch is not a function
。
setup() {
const store = useStore;
const feature = ref();
const featureSelected = (newFeature) => {
feature.value = newFeature;
store.dispatch("setPlot", { geometry: newFeature });
};
return { feature, featureSelected };
},
Run Code Online (Sandbox Code Playgroud) 如果您查看 react-datepicker 的默认实现,则每个月都会突出显示本月的某一天。有没有办法只突出显示/着色当前月份的日期,而不突出显示所有其他月份的日期?
如果您查看第一张图片,8 月 6 日将突出显示,因为它是当前日期。但也强调了 9 月 6 日。
我有一个投资组合的html文件.每个投资组合项目如下所示:
<div class="item">
<div class="portfolio-item">
<a href="img/portfolio-item-1.jpg" data-lightbox="image-1"><img src="img/portfolio-item-1.jpg"></a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
是否有一种简单易行的循环方式.因此,每次数字改变时,我都会创建多个div.所以我第二次得到投资组合项目2.
所以我得到这个异常:
引起原因:android.database.sqlite.SQLiteException:near“to”:语法错误(代码1):,编译时:CREATE TABLE betalingen(_id INTEGER PRIMARY KEY,id TEXT,amount TEXT,to TEXT,from TEXT,context TEXT )
在我的 sqlite 类中,我编写文本来创建数据库,如下所示:
**public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "betalingen.db";
private static final String TEXT_TYPE = " TEXT";
private static final String COMMA_SEP = ",";
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + FeedReaderContract.FeedEntry.TABLE_NAME + " (" +
FeedReaderContract.FeedEntry._ID + " INTEGER PRIMARY KEY," +
FeedReaderContract.FeedEntry.COLUMN_ID + TEXT_TYPE + COMMA_SEP +
FeedReaderContract.FeedEntry.COLUMN_AMOUNT + TEXT_TYPE + COMMA_SEP +
FeedReaderContract.FeedEntry.COLUMN_TO …
Run Code Online (Sandbox Code Playgroud) javascript ×4
vue.js ×3
css ×2
d3.js ×2
express ×2
html ×2
reactjs ×2
tailwind-css ×2
android ×1
datepicker ×1
dto ×1
html-select ×1
loops ×1
material-ui ×1
node.js ×1
sqlite ×1
syntax ×1
typescript ×1
vue-i18n ×1
vuejs3 ×1
vuex ×1
vuex4 ×1