use gloo::console::log;
use std::ops::Deref;
use web_sys::FileList;
use yew::prelude::*;
let filelist: UseStateHandle<Vec<FileList>> = use_state(|| vec![]);
Callback::from(move |event: DragEvent| {
event.prevent_default();
let files = event.data_transfer().unwrap().files();
// log!(files);
let 开发者_StackOverflow中文版cloned_filelist = filelist.clone();
let mut filelistvalue = *cloned_filelist.deref().clone();
// filelist_vec.push(files);
})
*cloned_filelist.deref().clone()
gives a slice [FileList]
instead of Vec<FileList>
How can I use get a Vec
from use_state
and mutate it?
You can use to_vec
for that:
use yew::prelude::*;
#[derive(Clone)]
struct FileList;
#[function_component(Main)]
fn main() -> Html {
let filelist: UseStateHandle<Vec<FileList>> = use_state(|| vec![]);
let files = FileList;
let mut cloned: Vec<_> = filelist.to_vec();
cloned.push(files);
filelist.set(cloned);
todo!()
}
精彩评论