我已经尝试过这里的其他答案的例子,但我没有成功!
我创建了一个反应形式(即动态),我想在任何给定时间禁用某些字段.我的表格代码:
this.form = this._fb.group({
name: ['', Validators.required],
options: this._fb.array([])
});
const control = <FormArray>this.form.controls['options'];
control.push(this._fb.group({
value: ['']
}));
Run Code Online (Sandbox Code Playgroud)
我的HTML:
<div class='row' formArrayName="options">
<div *ngFor="let opt of form.controls.options.controls; let i=index">
<div [formGroupName]="i">
<select formArrayName="value">
<option></option>
<option>{{ opt.controls.value }}</option>
</select>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我减少了代码以方便.我想禁用select类型的字段.我试着做以下事情:
form = new FormGroup({
first: new FormControl({value: '', disabled: true}, Validators.required),
});
Run Code Online (Sandbox Code Playgroud)
不工作!有没有人有建议?
是否有可能检测到变量的变化?
我有以下内容:
@Input('name') name: string;
我想在这个变量'name'中发生变化时调用一个函数.
可能吗?
我有一个父组件和一个子组件。子组件位于父组件的对话框内。并且显示或隐藏此对话框。
我的父组件
<template>
<div>
<v-dialog v-model="dialog">
<product-form></product-form>
</v-dialog>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
我的子组件(产品形式)
<template>
<div>
.....
<input type="text" v-model="data">
.....
</div>
</template>
<script>
export default {
data: () => ({
data: '',
}),
methods:{
onSubmitProduct(){
//send data to server
}
},
}
</script>
Run Code Online (Sandbox Code Playgroud)
每当显示对话框时,我都需要清除子窗体。问题是我通过父组件显示对话框。注意:我不想在子组件中使用 v-model,因为我需要从子组件而不是父组件将数据发送到服务器。
有人能帮我吗?
* **解决方案***
我能够使用 ref 解决问题。我不知道我的解决方案是否与良好做法背道而驰。但这是我能做到的最好的。
//parent component
<template>
<div>
<v-dialog v-model="dialog">
<product-form ref="childComponent"></product-form>
</v-dialog>
</div>
</template>
this.$refs.childComponent.resetForm();
Run Code Online (Sandbox Code Playgroud)
——
//child compopnent
<template>
<div>
.....
<input type="text" v-model="data">
.....
</div>
</template>
<script>
export default {
data: () …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 typescript 使用 sequelize 部署 nestJs。
我正在关注本教程:
https://docs.nestjs.com/techniques/database#sequelize-integration
[00:22:10] Starting compilation in watch mode...
node_modules/sequelize-typescript/dist/model/model/model.d.ts:10:31 - error TS2417: Class static side 'typeof import("/var/www/vhosts/curem/temp/node_modules/sequelize-typescript/dist/model/model/model").Model' incorrectly extends base class static side 'typeof import("/var/www/vhosts/curem/temp/node_modules/sequelize/types/lib/model").Model'.
The types returned by 'init(...)' are incompatible between these types.
Type 'Model<any, any>' is not assignable to type 'MS'.
'MS' could be instantiated with an arbitrary type which could be unrelated to 'Model<any, any>'.
10 export declare abstract class Model<TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes> …Run Code Online (Sandbox Code Playgroud) 我正在将rabbitmq与nestjs一起使用。我需要将消息从一个队列复制到另一个队列。我在rabbitmq上建立了一个交换以使其正常工作。但是如何改变nestjs中rabbitmq的交换呢?
我的 API 网关
我当前在nestjs中的rabbitmq配置:
constructor( ) {
this.rabbitmq = ClientProxyFactory.create({
transport: Transport.RMQ,
options: {
urls: [`amqp://${this.configService.get<string>('RABBITMQ_USER')}:${this.configService.get<string>('RABBITMQ_PASSWORD')}@${this.configService.get<string>('RABBITMQ_URL')}`],
queue: 'students'
}
})
}
createStudent(@Body() body: CreateStudentDto): Observable<any> {
return this.rabbitmq.send('createStudent', body)
}
Run Code Online (Sandbox Code Playgroud)
我的客户
@MessagePattern('createStudent')
async createStudent(@Payload() student: Student, @Ctx() context: RmqContext) {
const channel = context.getChannelRef()
const originalMsg = context.getMessage()
try {
let response = await this.studentService.createStudent(student)
await channel.ack(originalMsg)
return response;
} catch(error) {
this.logger.log(`error: ${JSON.stringify(error.message)}`)
const filterAckError = ackErrors.filter(ackError => error.message.includes(ackError))
if (filterAckError.length > 0) {
await channel.ack(originalMsg)
}
} …Run Code Online (Sandbox Code Playgroud) 我正在和朋友讨论在亚马逊存储文件的最佳方式。
我相信 s3 存储桶是将静态文件保存为网站图像的最佳方式。
但朋友们说这不是使用 s3 的最佳方式,因为多次请求此图像的成本很高。
我需要知道保存将在我的网站(位于 EC2 实例内)内渲染的图像的最佳位置。
有人可以澄清这个疑问吗?在有很多请求的站点中将图像保存在 S3 内的成本昂贵吗?
如何让我的测试等待我的api的结果?我正在使用vue和jest来测试我的组件.
我想测试将客户端写入数据库的方法.在我的组件中,我有以下方法:
methods: {
onSubmitClient(){
axios.post(`urlApi`, this.dados).then(res => {
return res;
})
}
}
Run Code Online (Sandbox Code Playgroud)
在我的测试中
describe('login.vue', () => {
let wrapper
beforeAll(()=>{
wrapper = mount(client, {
stubs: ['router-link'],
store,
data() {
return {
dados: {
name: 'tes name',
city: 'test city'
},
};
}
})
})
it('store client', () => {
res = wrapper.vm.onSubmitLogin()
console.log(res);
})
})
Run Code Online (Sandbox Code Playgroud)
我的测试不等待API调用完成.我需要等待API调用才能知道测试是否有效.如何让我的测试等待API返回?
angular ×2
nestjs ×2
vue.js ×2
vuejs2 ×2
amazon-ec2 ×1
amazon-s3 ×1
jestjs ×1
rabbitmq ×1
typescript ×1
unit-testing ×1