先上代码
const Article = {
template:'article
'
}
const News = {
template:'\
- \
\
{{ item.title }}{{ item.date }}
\
{{ item.detail }}
\
\
\
\
'}
const router = new VueRouter({
routes:[
{path:'/article', component: Article},
{path:'/',component: News}
]
})
var box = new Vue({
router,
el: "#box",
data: {
items: []
},
...
代码大概就是这样,想通过vue-router判断不同路径在router-view中渲染不同内容,但是像上面这么写会报错:
[Vue warn]: Property or method "items" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
(found in anonymous component - use the "name" option for better debugging messages.)
不太清楚这个问题是什么意思,希望大神们给点解决办法,或者用其他路由方法也可以 只要跳转时不重复刷新页面就好。
还有个问题就是,vue-router 的history模式 说是需要后端配置否则会404 我按照官网的写法用node中间件把跳转路径都重新定向到当前页面了,虽然跳转是解决了,但是每次跳转都重新载入页面并不是局部刷新了 有什么解决办法吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
News引用的items应该是News这个组件的数据,而你的items是注册在根实例里的。试试这样: