【问题标题】:Vue js filter not compatible on some mobile deviceVue js过滤器在某些移动设备上不兼容
【发布时间】:2019-01-07 10:23:23
【问题描述】:

我现在在我的 webview 应用程序上使用 vue js 只是为了过滤用户搜索。在我在Samsung SM-G530H 上运行我的应用程序之前,一切都运行良好,我收到一条错误消息Uncaught SyntaxError: Unexpected token (,我检查了一切正确,它可以在除旧设备之外的其他设备上运行。请问如何让它在所有设备上兼容?

new Vue({
      el: '#SearchVueContenPage',
        data() {
            return {
                q: '',
                total_result: 0,
                searchProduct: null,
                loading: false,
                sort_filter: ``,
                URL: ajax_appserver("public", "_api/searchProduct.php")
            }
        },

        computed: {
            search() {
              if (!this.searchProduct) {
                return []
              }

              if (!this.q) {
                  this.total_result = 0;
                return this.searchProduct.recent.slice(0,4);
              }
              var query = this.q.toLowerCase();
              var searchResult = this.searchProduct.result.filter(row => row.product_name.toLowerCase().includes(query) || row.business_name.toLowerCase().includes(query));
              this.total_result = searchResult.length;
              return searchResult;
            }
        },

        mounted() {
            this.loading = true;
            this.fetchData().then(() => {
             this.loading = false
            });
        },

        methods: {
            sortStatus: function(status) {
                   this.sort_filter = status;
             },

            async fetchData() {

                ajax_fetch(this.URL).then(json => {
                    this.searchProduct = json;
                    Vue.nextTick(function(){
                        //Store object in IndexDb
                    }.bind(this));
                });
            }
      }
});

【问题讨论】:

    标签: javascript vue.js compatibility


    【解决方案1】:

    似乎正在发生错误,因为您正在尝试运行使用“方法定义”语法的代码。

    Method definitions on MDN

    出现此错误的原因是“方法定义”是 JS 中相对较新的功能/语法,并非所有浏览器都支持。

    解决方案是使用 babel 将代码预编译为 ES5。 如果你使用 VUE-CLI,你已经有了 webpack,你只需要配置它来输出 ES5 代码。

    【讨论】:

    • "使用 babel 将代码预编译为 ES5" 我该怎么做,有什么在线工具可以帮助我吗?
    • 你如何执行你的代码?你使用'vue-cli'吗?
    • 我在这里babeljs.io 完成了,但我仍然收到错误ReferenceError {stack: (...), message: "regeneratorRuntime is not defined"}
    • 我在我的页面上包含了 vue.js javascript 库并编写了我的代码,还有其他更好的方法可以执行它吗?
    • “正确”的方法是使用 vue-cli 生成一个应用程序(您可以在文档中阅读如何操作)或通过 babel 传递您的所有代码。
    猜你喜欢
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 2019-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多