new Vue({
el: "#app",
data: {
value: "text",
},
computed:{
all: function({value}){
return value
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
{{ value }}
<br>
{{ all }}
</div>
Didn't see this usage on Vue document.
but I saw this on my project, why this usage could work?
computed:{
all: function({value}){
return value
}
}
First i think when function didn't get argument, would take "this" be the argument. see below.
but is wrong. so why computed didn't get argument, Destructuring assignment the parameter still work?
var value = "couldn't fly";
function ref ({value}){
console.log(value)
}
ref({
value : "could fly"
})
// didn't get window
try{
ref();
}catch(e){
console.log('error')
}
// ===================================================
class cal {
constructor(){
value : "couldn't walk"
}
ref({value}){
console.log(value, "in Class")
}
}
let calRef = new cal;
calRef.ref({
value: "could walk"
})
// didn't get the constructor value
try{
calRef.ref()
}catch(e){
console.log('error')
}