mirror of https://github.com/sveltejs/svelte
Merge pull request #1345 from sveltejs/gh-1069
use destructuring syntax for computed props in v2 mode - fixes #1069pull/1346/head
commit
6249fa6bc8
@ -0,0 +1,20 @@
|
||||
<p>{scale(x)}</p>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data: () => ({
|
||||
x: 5,
|
||||
domain: [ 0, 10 ],
|
||||
range: [ 0, 100 ]
|
||||
}),
|
||||
|
||||
computed: {
|
||||
scale: ({ domain, range }) => {
|
||||
return num => {
|
||||
const t = domain[0] + ( num - domain[0] ) / ( domain[1] - domain[0] );
|
||||
return range[0] + t * ( range[1] - range[0] );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,14 @@
|
||||
<span>{state}</span>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
x: 'waiting'
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
state: ({ x }) => x
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,9 @@
|
||||
<p>{foo}</p>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
computed: {
|
||||
foo: ({ a = 1 }) => a * 2
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,28 @@
|
||||
<p>{x}</p>
|
||||
|
||||
<script>
|
||||
let _x;
|
||||
|
||||
function getX () {
|
||||
return _x;
|
||||
}
|
||||
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
y: 1
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
xGetter ({ y }) {
|
||||
_x = y * 2;
|
||||
return getX;
|
||||
},
|
||||
|
||||
x ({ xGetter }) {
|
||||
return xGetter();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,16 @@
|
||||
<p>{a} + {b} = {c}</p>
|
||||
<p>{c} * {c} = {cSquared}</p>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data: () => ({
|
||||
a: 1,
|
||||
b: 2
|
||||
}),
|
||||
|
||||
computed: {
|
||||
c: ({ a, b }) => a + b,
|
||||
cSquared: ({ c }) => c * c
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue