我有两个组件:列表和详细信息
在列表组件中,我想渲染多个细节组件.
list.component.ts
@Component({
selector: 'detail',
templateUrl: './detail.component.html'
})
export class DetailComponent {
@ViewChild('details') details;
public items = {
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
list.component.html
<detail *ngFor="let item of items" #details></detail>
Run Code Online (Sandbox Code Playgroud)
注意#details tempalte引用变量.我想访问所有细节组件.可以使#details变量成为一个数组吗?
我在 Vue 路由器中的路线:
{ path: 'articles/create', component: () => import('Detail.vue') },
{ path: 'articles/:id/edit', component: () => import('Detail.vue') },
Run Code Online (Sandbox Code Playgroud)
如您所见,我Detail.vue在两条路线上渲染相同的 Vue 组件。
当 URL从例如变为时,如何“强制”Vue 销毁并重新创建Detail.vue组件?/articles/5/edit/articles/create
class Test {
@First()
@Second()
public someAttribute;
}
var t = new Test();
var decorators = t.getListOfAttributeDecorators("someAttribute");
console.log(decorators); // [First, Second]
Run Code Online (Sandbox Code Playgroud)
我想实现“getListOfAttributeDecorators”函数,但不知道如何实现。或者有没有其他方法可以获取属性装饰器列表?
我为 Vue 2 编写了一个“加载状态”mixin:
export default {
props: {
loading: {
type: Boolean,
default: false
},
},
data () {
return {
innerLoading: false,
}
},
mounted () {
this.innerLoading = !!this.loading
},
methods: {
startLoading () {
this.$emit('update:loading', this.innerLoading = true)
},
stopLoading () {
this.$emit('update:loading', this.innerLoading = false)
},
},
computed: {
isLoading () {
return !!this.innerLoading
},
isNotLoading () {
return !this.innerLoading
},
},
watch: {
loading (loading) {
this.innerLoading = !!loading
},
}
}
Run Code Online (Sandbox Code Playgroud)
我将此混合用于其他组件以保持loading …