VueJS路线未定义

时间:2018-01-24 21:53:19

标签: vue.js

我正在试图弄清楚如何抓住当前路线,因为它说没有定义$ route。我已经导入了包并尽我所能地应用它,并且无法使其正常工作。

有没有人使用过这个软件包,可以看到我的问题?

<template>
<div class="row">
    <div class="col-12 col-md-6">
        <div class="form-group">
            <label class="control-label" for="start_date">Schedule Type</label>
            <select class="form-control" name="schedule_type" v-model="selected">
                <option value="1">Show All Projects</option>
                <option value="2">Show Scheduled Projects</option>
                <option value="3">Show Unscheduled Projects</option>
            </select>
        </div>
    </div>
    <div class="col-12 col-md-6">
        <div class="row">
           <div class="col-12 col-md-6">
                <div class="form-group" v-bind:class="{ 'hidden-mobile': isDisabled }">
                    <label class="control-label" for="start_date">Start Date (Start)</label>
                    <input class="form-control" type="date" id="start_date" name="range[start]" :disabled="isDisabled">
                </div>
            </div>
            <div class="col-12 col-md-6" v-bind:class="{ 'hidden-mobile': isDisabled }">
                <div class="form-group">
                    <label class="control-label" for="start_date_end">Start Date (End)</label>
                    <input class="form-control" type="date" id="start_date_end" name="range[end]" :disabled="isDisabled">
                </div>
            </div>
        </div> 
    </div>
 </div>
</template>

<script>

export default {
    data () {
        return {
            selected: 1,
            class: ''
        }
    },
    created() {
        console.log($route.query);
    }, 
    computed: {
        isDisabled() {
          return (this.selected == 1 || this.selected == 3);
        },
    }
}
</script>

更新了App.js

window.Vue = require('vue');
var route = require('vue-router');
Vue.use(route);

const app = new Vue({
  el: "#app",
  components: {

 }
});

1 个答案:

答案 0 :(得分:3)

在脚本中使用它:

this.$route.path

仅在模板中使用$route,如:

  • inside&#34;字符串插值,如:{{$ route.path}}
  • 在属性绑定中,....

对于你的情况,它将是:

created () {
    console.log(this.$route.path);
}