一般而言,Vue 新手,目前使用 3.2.37,我可能误解了composition api\xe2\x80\x99s DefineExpose 指令的正确用法,如下所述: https: //vuejs.org/api/sfc-script-setup.html #defineexpose
\n还有一些线程,解释如何从内部公开成员,<script setup>例如Calling method on Child Component - Composition API。但不知何故,我无法设法version公开子组件的常量引用HelloWorld,以便可以将其version插值到app组件中。
应用程序.vue:
\n<script setup>\nimport HelloWorld from \'./components/HelloWorld.vue\'\n</script>\n\n<template>\n <main>\n <HelloWorld />\n <h1>version:{{HelloWorld.version}}</h1>\n </main>\n</template>\nRun Code Online (Sandbox Code Playgroud)\n你好世界.vue:
\n<script setup>\nimport { ref } from \'vue\';\n\nconst version = ref(\'1.0.0\');\n\ndefineExpose({ version });\n</script>\n\n<template>\n <div>\n <h3> You\xe2\x80\x99ve successfully created a project with Vue.js and Vuetify. </h3>\n </div>\n</template>\nRun Code Online (Sandbox Code Playgroud)\n图像:\n版本 1.0.0 未显示
\n我是新手做出反应,我正在从Lynda的一个例子中学习子类.我正在创建一个名为的新子组件类,aptList并使用this.props.eachItem.ownerName迭代JSON文件中的每个索引ownerName作为属性.
这是我在浏览器中运行时遇到的错误.获取数据但未prop根据错误识别
然而,反应控制台似乎正在获得JSON
这是Lynda教授的代码
var React = require('react');
var ReactDOM = require('react-dom');
var createReactClass = require('create-react-class');
var aptList = createReactClass({
render: function(){
return(
<li>{ this.props.eachItem.ownerName }</li>
);
}
});
var MainInterface = createReactClass({
getInitialState: function(){
return {
title: 'Items',
show: function(x){
if(x>10){
return true
}
else {
return false
}
},
myData: []
}
},
componentDidMount: function(){
this.serverRequest = $.getJSON('static/scripts/src/myData.json', function(results){
var tempData = results;
this.setState({
myData: tempData
});
}.bind(this));
},
componentWillUnmount: …Run Code Online (Sandbox Code Playgroud) 嗨,社区,我在理解 dagger 2 以新方式添加子组件时遇到问题(在 dagger 2.7 中添加)。请参阅下面的示例:
@Component(modules = {AppModule.class, MainActivityBinder.class})
@Singleton
interface AppComponent
{
inject(MyApplication _)
}
@Subcomponent(modules = ActivityModule.class)
interface ActivitySubcomponent
{
inject(MainActivity _)
@Subcomponent.Builder
interface Builder
{
@BindInstance
Builder activity(Activity activity)
ActivitySubcomponent build();
}
}
Run Code Online (Sandbox Code Playgroud)
初始步骤:我AppComponent提供的是我的根组件,它提供AppModule单例(改造、okhttp 等)。在ActivitySubcomponent我提供ActivityModule的具有指定给该活动的依赖项。现在必须将子组件添加到AppComponent,因此我以新的方式创建名为 的指定模块MainActivityBinder,该模块具有注释@Module.subcomponents 并指向绑定子组件,但我有第一个问题,该绑定模块的主体中应该包含什么?
@Module(subcomponents = ActivitySubcomponent.class)
public class MainActivityBinder
{
//what body of this class should be ??
}
Run Code Online (Sandbox Code Playgroud)
我知道,这个想法是我可以绑定子组件或它们的构建器。第二个问题什么时候绑定构建器,什么时候绑定子组件?例如我ActivitySubcomponent需要的活动上下文,所以我创建了提供上下文的构建器,ActivityModule在这种情况下最好在MainActivityBinder构建器中提供?第三个问题如何调用组件构建器以及如何获取应用组件的子组件?在标准子组件工厂中,我添加到AppComponent返回子组件的方法中,我可以定义参数(例如给出活动上下文,如下所列)
@Component(modules …Run Code Online (Sandbox Code Playgroud) 我有一个使用 Blazor InputFile 组件作为子组件的组件。
当我选择一个文件时,按预期调用 OnChange 处理程序。但是,如果我两次选择同一个文件,则不会再次调用 OnChange 处理程序(我猜这符合预期,因为选择没有改变,但是我的用例需要这个)。
因此,我想如果我可以选择一个文件并调用 OnChange 处理程序并在 OnChange 处理程序中“重置”所选文件,那么即使再次选择了相同的文件,我也应该获得对处理程序的新调用。
我不知道如何重置 InputFile(子)组件中的文件选择。调用this.StateHasChanged()处理程序不会导致 InputFile 组件重新呈现。
如果没有 JSInterop 并手动将 DOM 输入元素的值字段设置为“”,这是否可行(这是否可行)?
我的组件:
@using stuff;
<div class="drag-drop-area">
Drag and drop file here
<InputFile OnChange="@OnInputFileChange"></InputFile>
</div>
@code {
[Parameter]
public String SomeParam { get; set; } = "";
private async Task OnInputFileChange(InputFileChangeEventArgs e) {
// do stuff with file
// do _something_ here to reset InputFile
this.StateHasChanged(); //<-- this doesn't cause InputFile re-render
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我尝试这样做包括:
await Task.Delay(1); …