0

使用 Vue-router 在 Vue 中添加路由时遇到问题。我知道这是一个警告,但我仍然需要解决这个问题,因此我们将不胜感激。我正在使用 laravel vue,我是初学者。 我尝试了几乎每个 StackOverflow 链接来删除此警告,但失败了。下面你可以看到我的代码。

应用程序.js


window.Vue = require('vue');
import VueMaterial from 'vue-material'
import 'vue-material/dist/vue-material.min.css'
import moment from 'moment'
import $ from 'jquery'
import 'datatables.net'
import routes from './components/includes/routes'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
Vue.use(VueMaterial)


import App from './components/views/App'



Vue.filter('formatDate', function(value) {

    if (value) {

      return moment(String(value)).format('L (LT)')

    }

  });


Vue.component('example-component', require('./components/ExampleComponent.vue'));
Vue.component('app-component', require('./components/views/App.vue').default);
Vue.component('donations-component', require('./components/views/Donations.vue'));
Vue.component('needy-component', require('./components/views/Needy.vue'));


var router = new VueRouter({
  routes: routes,
  mode: 'history'
})



const app = new Vue({
    el: '#app',
    components: { App },
    router,
});

路由.js

import Needy from '../views/Needy'

const routes = [
        {
            path: '/home',
            name: 'donations',
            component: Donations,
        },
        {
            path: '/needy',
            name: 'needy',
            component: Needy,
        },
    ];

  export default routes

应用程序.vue

  <div class="page-container md-layout-column">
    <md-toolbar class="md-primary">
      <md-button class="md-icon-button" @click="showNavigation = true">
        <md-icon>menu</md-icon>
      </md-button>
      <span class="md-title">My Title</span>

      <div class="md-toolbar-section-end">
        <md-button @click="showSidepanel = true">Favorites</md-button>
      </div>
    </md-toolbar>

    <md-drawer :md-active.sync="showNavigation" md-swipeable>
      <md-toolbar class="md-transparent" md-elevation="0">
        <span class="md-title">My App name</span>
      </md-toolbar>

      <md-list>
        <md-list-item>
          <md-icon>move_to_inbox</md-icon>
          <router-link :to="{ name: 'donations' }" class="md-list-item-text">Donations</router-link>
        </md-list-item>
        <md-list-item>
          <md-icon>move_to_inbox</md-icon>
          <router-link :to="{ name: 'needy' }" class="md-list-item-text">Needy</router-link>
        </md-list-item>
      </md-list>
    </md-drawer>

    <md-content>
        <router-view></router-view>
    </md-content>
  </div>
</template>

<script>
  export default {
      data (){
          return {
              showNavigation: false,
            showSidepanel: false
          }
      }
  }
</script>

<style lang="scss" scoped>

</style>

浏览器控制台错误

[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the 
parent component re-renders. Instead, use a data or computed property based on the prop's value. 
Prop being mutated: "to"

found in

---> <RouterLink>
       <MdRipple> at src/components/MdRipple/MdRipple.vue
         <MdListItemContent> at src/components/MdList/MdListItem/MdListItemContent.vue
           <MdListItemDefault> at src/components/MdList/MdListItem/MdListItemDefault.vue
             <MdList> at src/components/MdList/MdList.vue
               <MdDrawer> at src/components/MdDrawer/MdDrawer.vue
                 <AppComponent> at resources/js/components/views/App.vue
                   <Root> vue.js:597:15
[Vue warn]: $attrs is readonly.

found in

---> <RouterLink>
       <MdRipple> at src/components/MdRipple/MdRipple.vue
         <MdListItemContent> at src/components/MdList/MdListItem/MdListItemContent.vue
           <MdListItemDefault> at src/components/MdList/MdListItem/MdListItemDefault.vue
             <MdList> at src/components/MdList/MdList.vue
               <MdDrawer> at src/components/MdDrawer/MdDrawer.vue
                 <AppComponent> at resources/js/components/views/App.vue
                   <Root> vue.js:597:15
[Vue warn]: $listeners is readonly.

found in

---> <RouterLink>
       <MdRipple> at src/components/MdRipple/MdRipple.vue
         <MdListItemContent> at src/components/MdList/MdListItem/MdListItemContent.vue
           <MdListItemDefault> at src/components/MdList/MdListItem/MdListItemDefault.vue
             <MdList> at src/components/MdList/MdList.vue
               <MdDrawer> at src/components/MdDrawer/MdDrawer.vue
                 <AppComponent> at resources/js/components/views/App.vue
                   <Root>
4

0 回答 0