在Vue.js文档中有一个如下例子:
var vm = new Vue({
el: '#demo',
data: {
firstName: 'Foo',
lastName: 'Bar',
fullName: 'Foo Bar'
},
watch: {
firstName: function (val) {
this.fullName = val + ' ' + this.lastName
},
lastName: function (val) {
this.fullName = this.firstName + ' ' + val
}
}
})
Run Code Online (Sandbox Code Playgroud)
上面的代码是必要的和重复的.将其与计算属性版本进行比较:
var vm = new Vue({
el: '#demo',
data: {
firstName: 'Foo',
lastName: 'Bar'
},
computed: {
fullName: function () {
return this.firstName + ' ' + this.lastName
}
}
})
Run Code Online (Sandbox Code Playgroud)
观察者比计算属性更合适的情况是什么?我该如何决定选择哪个?文档一直说它更"通用",但并没有真正实现其目的.
我在/entries/12
路上。在/entries/13
用户单击下一个按钮时,我想在同一个组件上推送。
代码是这样的:
//e is the next page number.
this.$router.push({ name: 'Entries', params: { pageNum: e }});
Run Code Online (Sandbox Code Playgroud)
我得到以下错误:
如果我尝试不同的路线。
全码:
<template>
<div class="entries">
<generic-entries @clicked="clicked" ></generic-entries>
</div>
</template>
<script>
import GenericEntriesComp from '@/components/GenericEntriesComp';
export default{
name: 'entries-comp',
components: {genericEntries: GenericEntriesComp},
mounted(){
var params = {id : this.$route.params.pageNum}
this.$store.dispatch("getEntries",params);
},
methods: {
clicked(e){
this.$router.push({ name: 'Entries', params: { pageNum: e.toString() }});
},
loadData(){
var params = {pageNum : this.$route.params.pageNum}
this.$store.dispatch("getEntries", params)
}
},
computed: {
items(){
return this.$store.state.entries …
Run Code Online (Sandbox Code Playgroud) 在Mozilla的页面迭代器和生成器上有一个声明:
虽然自定义迭代器是一个有用的工具,但由于需要显式维护其内部状态,因此需要仔细编程.生成器提供了一个强大的替代方案:它们允许您通过编写可以维持其自身状态的单个函数来定义迭代算法.
关于上述说明,不可能在没有发生器的情况下编写迭代算法,例如:
Array[Symbol.iterator] = function(){
return {
next: function(){
//logic
return {
value: "",
done:false
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
无法理解我的头脑.有人可以解释一下他们创造替代品的主要原因是什么,对我来说似乎并没有什么不同.
Javascript 面试题: [1,2,3].sum()
在不使用Prototype
和的情况下运行精确的代码Object.defineProperty
,Object.defineProperties
。
既然这是一个面试问题,我假设有办法让它发挥作用?
任何帮助/指点方向表示赞赏。
谢谢
我在下面的查询中,我想用knex fromat表示此查询。我已经通过usng raw
函数使其工作了,但是我很好奇是否可以使用knex样式。
SELECT t.id, t.title, s.userId
FROM title t LEFT JOIN
subscribe s ON t.id = s.titleId AND s.userId = 1;
Run Code Online (Sandbox Code Playgroud)