Node.js/nuxt/传值:修订间差异
来自康健生活
| 第1行: | 第1行: | ||
== 父传子 == | |||
<syntaxhighlight lang="javascript"> | |||
Insert comment here | |||
</syntaxhighlight> | |||
== 兄弟传值 == | == 兄弟传值 == | ||
现在有一个需求是路由跳转页面,然后刷新数据,但是路由地址不变,变的是路由地址后面 query 的参数。 | 现在有一个需求是路由跳转页面,然后刷新数据,但是路由地址不变,变的是路由地址后面 query 的参数。 | ||
| 第80行: | 第84行: | ||
}, | }, | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
== 事件车 == | == 事件车 == | ||
{{hc|eventBus.js|<syntaxhighlight lang="javascript"> | {{hc|eventBus.js|<syntaxhighlight lang="javascript"> | ||
2020年7月26日 (日) 17:14的版本
父传子
Insert comment here
兄弟传值
现在有一个需求是路由跳转页面,然后刷新数据,但是路由地址不变,变的是路由地址后面 query 的参数。
http://localhost:3000/search?pageView=SearchAll
子传父,父传子
navmenu -> index -> list -> listleft
父亲:index.vue 儿子:list.vue list 的儿子,父亲的孙子:listLeft.vue 儿子:navmenu.vue
index.vue
<NavMenu @searchPageViewValue="pageViewValue"/>
<List :searchPageViewValue="searchPageViewValue"/>
data () {
return {
searchPageViewValue: 'searchAll'
}
},
components: {
NavMenu,
List
},
props: {
pageView: {
type: String,
default: 'SearchAll'
},
list.vue
<ListLeft :searchPageViewValue="searchPageViewValue"/>
<listRight/>
props: {
searchPageViewValue: {
type: String,
default: 'searchAll'
}
},
listLeft.vue
<ListLeftArticle v-if="searchPageType === 'SearchAll' || searchPageType === 'SearchQa'"/>
<ListLeftFile v-if="searchPageType === 'SearchAll'"/>
<ListLeftUser v-if="searchPageType === 'SearchAll' || searchPageType === 'SearchUser'"/>
<ListPagination/>
navmenu.vue
<nuxt-link
:key="$route.path+'?pageView=SearchAll'"
:to="{path:'/search',query:{pageView:'SearchAll'}}"
class="tags-li-title is-active"
>综合 (24)
</nuxt-link>
watch: {
$route (to, from) {
this.$emit('searchPageViewValue', this.pageView)
}
},
路由
第二种方法是直接监听路由
listLeft.vue
<ListLeftArticle v-if="searchPageType === 'SearchAll' || searchPageType === 'SearchQa'"/>
<ListLeftFile v-if="searchPageType === 'SearchAll'"/>
<ListLeftUser v-if="searchPageType === 'SearchAll' || searchPageType === 'SearchUser'"/>
<ListPagination/>
watch: {
$route (to, from) {
this.searchPageType = this.$route.query.pageView
}
},
事件车
eventBus.js
import Vue from 'vue'
export default new Vue();
AllCountry.vue
import EventBus from "@/router/eventBus";
mounted() {
this.allCountryEvent();
},
methods: {
renderData() {
...
allCountryEvent() {
EventBus.$emit('allCountry', {
isCountry: this.isCountry,
isDepartment: this.isDepartment,
isCountryValue: this.isCountryValue,
isDepartmentValue: this.isDepartmentValue,
})
}
HospitalList.vue
import EventBus from "@/router/eventBus";
methods: {
...
allCountryMessage() {
let _self = this;
EventBus.$on('allCountry', (message) => {
_self.allCountryCache = message;
_self.currentPage = 1;
_self.getData(
message.isCountry,
message.isCountryValue,
message.isDepartment,
message.isDepartmentValue,
_self.currentPage
)
})
}
No categories