为什么foreach循环只读?我的意思是你可以获取数据,但不能增加++或减少 - .它背后的任何原因?是的我是初学者:)
〔实施例:
int[] myArray={1,2,3};
foreach (int num in myArray)
{
num+=1;
}
Run Code Online (Sandbox Code Playgroud) 我读了一篇关于Renderless Components的文章,它通过 $scopedSlots 属性将一个组件拆分为一个展示组件(视图部分)和一个无渲染组件(逻辑部分)。这是一个简单的标签组件。当您按 enter 时,您将添加一个新标签
<!DOCTYPE html>
<html>
<head>
<script src="http://vuejs.org/js/vue.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="app">
<custom-component v-model="tags">
<div slot-scope="{tags,addTag,newTag}">
<span v-for="tag in tags">
{{tag}}
</span>
<input type="text" @keydown.enter.prevent="addTag" v-model="newTag">
</div>
</custom-component>
</div>
<script>
Vue.component('custom-component',{
props:['value'],
data(){
return {
newTag:''
}
},
methods:{
addTag(){
this.$emit('input',[...this.value,this.newTag])
this.newTag = ''
}
},
render(h){
return this.$scopedSlots.default({
tags:this.value,
addTag:this.addTag,
newTag:this.newTag
})
}
})
new Vue({
el:'#app',
data:{
tags:[
'Test',
'Design'
]
}
})
</script> …Run Code Online (Sandbox Code Playgroud) 我在接受采访时被问到一个问题而且我无法回答...这是问题所在
我的回答是它的另一个名称object......这个问题的正确答案是什么......