是否可以将多个参数传递到 axtic_web 路由中?
// srv.rs (frag.)
HttpServer::new(|| {
App::new()
.route(
"/api/ext/{name}/set/config/{id}",
web::get().to(api::router::setExtConfig),
)
})
.start();
Run Code Online (Sandbox Code Playgroud)
// router.rs (frag.)
pub fn setExtConfig(
name: web::Path<String>,
id: web::Path<String>,
_req: HttpRequest,
) -> HttpResponse {
println!("{} {}", name, id);
HttpResponse::Ok()
.content_type("text/html")
.body("OK")
}
Run Code Online (Sandbox Code Playgroud)
对于只有一个参数的路由,一切正常,但对于本示例,我在浏览器中仅看到消息:wrong number of parameters: 2 expected 1,响应状态代码为 404。
我确实需要传递更多参数(从一个到三个或四个)......
我正在尝试选择表中的一行并发出所选项目。
选择一个将选择所有对象,但仅将第一个遇到的对象保存到模型中(作为selected变量)。
你有什么想法吗,我做错了什么?
<template>
<v-data-table
:headers="headers"
:items="items"
:search="search"
:loading="loading"
v-model="selected"
single-select
show-select
:options="{itemsPerPage:5}"
@item-selected="itemSelected"
>
<template v-slot:top>
<v-toolbar flat>
<v-text-field
v-model="search"
append-icon="mdi-magnify"
label="Search"
single-line
hide-details
></v-text-field>
</v-toolbar>
</template>
<template v-slot:item.name="{ item }">{{ item.name }}</template>
</v-data-table>
</template>
<script>
export default {
name: "variable-selector",
props: ["variables", "map", "index"],
data() {
return {
search: "",
selected: {},
loading: false,
items: [],
headers: [{ text: "Variable name", value: "name", sortable: true }]
};
},
methods: {
itemSelected(selection) {
if (selection.value) {
this.$emit("selected", …Run Code Online (Sandbox Code Playgroud) 我正在用 Rust 编写一些 Web api。我使用 XMLHttpRequest 从 JavaScript 发送 Unit8Array,我需要在服务器中以字节形式读取它们。
我的服务方式声明是:
pub fn user_login_bin(mut req: HttpRequest) {
println!("{:?}", req);
let mut stream = req.take_payload().take();
// error label: method not found in `actix_http::payload::Payload<()>`
let item = stream.poll().unwrap();
println!("{:?}", item);
HttpResponse::Ok().into()
}
Run Code Online (Sandbox Code Playgroud)
我如何从 actix_web::HttpRequest 有效负载读取 Vec ?
我尝试了一些示例代码,但它也不起作用:
req.take_payload()
// error label: method (fold) not found in `actix_http::payload::Payload<()>`
.fold(BytesMut::new(), move |mut body, chunk| {
body.extend_from_slice(&chunk);
Ok::<_, Error>(body)
})
.and_then(|bytes| {
println!("request body: {:?}", bytes);
});
Run Code Online (Sandbox Code Playgroud) 我有一个 Rust 项目,其结构如下:
\n\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Cargo.lock\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Cargo.toml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 routes\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 mod.rs\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 router_get.rs\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 router_post.rs\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.rs\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 server.rs\nRun Code Online (Sandbox Code Playgroud)\n\n我需要使用中的路由模块server.rs,但是当我尝试编译它时,它给了我一个错误:
error[E0432]: unresolved import `super::routes`\n --> src/server.rs:10:5\n |\n10 | use super::routes;\n | ^^^^^^^^^^ no `routes` in the root\nRun Code Online (Sandbox Code Playgroud)\n\n当我尝试使用routeswithmain.rs时mod routes,一切正常。但我需要在server.rs.
路线/mod.rs
\n\npub mod router_get;\npub mod router_post;\nRun Code Online (Sandbox Code Playgroud)\n rust ×3
actix-web ×2
datatable ×1
httprequest ×1
module ×1
payload ×1
select ×1
vue.js ×1
vuetify.js ×1