vue.js路由匹配问题

post传参的时候categorys 为啥不能识别呢?
图片描述
代码贴在下面:

<script>
export default {
  name: "app",
  components: {},
  data() {
    return {
      banner: require("@/assets/hottopic/banner.png"),
      data: [],
      filter: {
        page: {
          pageSize: 5,
          pageNumber: 1,
          totalSize: 100
        },
        categorys: ["小微企业专题"]
      }
    };
  },
  computed: {},
  methods: {
    getData() {
      this.filter.categorys = ["this.$route.params.id"]
      this.$API.post("/articlelist/query", this.filter).then(res => {
        console.log(res);
        this.data = res.list;
      });
    }
  },
  created() {
    if(this.$route.params.id){
      this.getData();
    }
  },
  mounted() {},
  watch:{
    "$route":"getData"
  }
};
</script>
阅读 2.7k
3 个回答
this.filter.categorys= [`${this.$route.params.id}`]

传入的数据带双引号,被认为是字符串

把引号去掉:

this.filter.categorys = [this.$route.params.id];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题