Exploring Vue.js on Safari mobile: Ensuring compatibility for seamless

I'm encountering an issue with a Vue.js component: it works perfectly on Firefox and Chrome, but fails on Safari and Safari mobile browsers.

Upon checking the console, I see the following error:

Object.values is not a function

Is there a workaround for this issue?

Below is the complete code snippet:

<template>
<div>
    <div v-for="(meal, i) in meals">
      <div class="panel panel-default">
          <div class="panel-body">
            <div class="col-sm-3">
              <img v-bind:src="all[i].image" class="img-circle" alt="Chicken" width="130px" height="130px">
            </div>
            <div class="col-sm-5">
              <div class="col-xs-12">
                <h3>{{meal}}</h3>
              </div>
            </div>
            <div class="col-sm-4" id="order_select">
              <select v-model="selected" v-model.lazy="creditsPerMeal[meal]" v-on:change="createSelection()">
                <option v-for="option in options" v-bind:value="option">
                  {{ option }}
                </option>
              </select>
            </div>
          </div>
      </div>
    </div>
    <div class="col-xs-12">
      <p>Credits used: {{creditsSum}}/{{credits}}</p>
    </div>
    <label>Dietary</label>
    <input type="textarea" name="dietary" v-model="dietary" class="form-control">
    <div class="col-xs-12">
        <div id="buy_now">
          <p>PRICE: £{{cost}}</p>
          <form action="/checkout" v-on:submit.prevent="onSubmit" method="post" id="buy_now_form">
              <input type="hidden" v-bind:value="select_meal" name="selected_meals" required>
              <input type="hidden" name="price" v-bind:value="cost">
              <input type="submit" value="BUY NOW" class="btn btn-default" :disabled="this.creditsSum != this.credits">
          </form>
        </div>
    </div>
    <div class="col-xs-12" v-if="this.credits==='10'">
        <div id="subscribe_now">
          <p>Subscribe</p>
              <label>4 Weeks</label>
              <button type="submit" class="btn btn-default" v-on:click="fourWeek" :disabled="this.creditsSum != this.credits">SUBSCRIBE</button>
              <label>8 Weeks</label>
              <button type="submit"  class="btn btn-default" v-on:click="eightWeek" :disabled="this.creditsSum != this.credits">SUBSCRIBE</button>
        </div>
    </div>
    <div class="col-xs-12" v-if="this.credits==='12'">
        <div id="subscribe_now">
          <p>Subscribe</p>
              <label>4 Weeks</label>
              <button type="submit" class="btn btn-default" v-on:click="fourWeek" :disabled="this.creditsSum != this.credits">SUBSCRIBE</button>
              <label>8 Weeks</label>
              <button type="submit"  class="btn btn-default" v-on:click="eightWeek" :disabled="this.creditsSum != this.credits">SUBSCRIBE</button>
        </div>
    </div>
    <div class="col-xs-12" v-if="this.credits==='15'">
        <div id="subscribe_now">
          <p>Subscribe</p>
              <label>4 Weeks</label>
              <button type="submit" class="btn btn-default" v-on:click="fourWeek" :disabled="this.creditsSum != this.credits">SUBSCRIBE</button>
              <label>8 Weeks</label>
              <button type="submit"  class="btn btn-default" v-on:click="eightWeek" :disabled="this.creditsSum != this.credits">SUBSCRIBE</button>
        </div>
    </div>
</div>
</template>

<script>
import axios from 'axios';
  export default {

    mounted() {
        console.log('Component ready.');

        console.log(JSON.parse(this.f));
        console.log(JSON.parse(this.a));

    },

    props: ['f','c', 'a'],

    name: 'credits',
    data: function () {
     var meals = JSON.parse(this.f)

     var all = JSON.parse(this.a)

     var creditsPerMeal = {}
     for (var i = 0; i < meals.length; i++) {
       creditsPerMeal[meals[i]] = 0
     }

      return {
        credits: this.c,
        meals,
        options: [1,2,3,4,5,6,7,8,9,10],
        select_meal: [],
        creditsPerMeal,
        all,
        dietary: "",
      }
    },
    computed: {
      creditsSum () {
        return Object.values(this.creditsPerMeal).reduce((a, b) => a + b, 0)
      },

      cost: function() {
          return this.cost = this.credits * 6;
      },

    },
    methods: {
      onSubmit() {

          axios.post('/check', {
                  selected_meals: this.select_meal,
                  dietary: this.dietary,
                  price: this.cost
              })
              .then(function(response) {
                  window.location = "/checkout";
              })
              .catch(function(error) {
                  console.log(error);
              });

      },

       createSelection: function (){
         this.select_meal = [];
           for (var i = 0; i < JSON.parse(this.f).length; i++) {
               this.select_meal.push({
                  food: JSON.parse(this.f)[i],
                  quantity: this.creditsPerMeal[JSON.parse(this.f)[i]]
               });
           }
       },

       fourWeek: function () {

         axios.post('/sub', {
                 selected_meals: this.select_meal,
                 package: 4,
                 credits: this.credits
             })
             .then(function(response) {
                 window.location = "/subscribe";
             })
             .catch(function(error) {
                 console.log(error);
             });

          },

          eightWeek: function () {

            axios.post('/sub', {
                    selected_meals: this.select_meal,
                    package: 8
                })
                .then(function(response) {
                    window.location = "/subscribe";
                })
                .catch(function(error) {
                    console.log(error);
                });

             },


     }
  }
</script>

Answer №1

The issue stems from the usage of Object.values, which is not universally supported by all web browsers. To address this, consider incorporating a polyfill for Object.values to ensure compatibility.

Further details can be found on this webpage

edit:

I notice that you are utilizing import in your code, which simplifies things.

Simply run npm install object.values

and include at the beginning of your code

import values from 'object.values';

if (!Object.values) { values.shim(); }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The output from $index in AngularJS appears to be incorrect and inconsistent

The question was too long so I edited it. Here is the angular code snippet in question: var mod = angular .module("myMod",[]) .controller("myCont",function($scope){ var obj = [ {name : "Monica", others : ...

Combine the values of identical keys from multiple objects in an array by utilizing the forEach method in JavaScript

I am currently working on refining a shopping basket function with Vue JS. One of the key features I need to implement is a subtotal calculation that multiplies the price and quantity values for each item and then combines them to create an overall subtota ...

Object responds to mouse click by rotating and moving through animation

Exploring the possibilities of three.js I'm attempting to create an animation (rotation/movement) for an object upon a mouse click event, however, I am not achieving the desired animation effects. Below is the code snippet that I have implemented. C ...

Time-sensitive Meteor Collections that automatically expire

I was thinking of using a Collection for this. It's crucial that the data gets cleared after a certain period of time, though. Is there a way to set an expiration date for a Meteor Collection? I need to empty the collection 30 seconds after making m ...

Mocha Test Runs Are Exceeding Time Limits

I've updated to Node.js 4.0 which now supports generators. After trying gulp-mocha-co and upgrading to Node 4.0 for generator support, I encountered timeouts in my mocha tests when trying to make them generator-friendly. Adding the * to my mocha unit ...

Problems encountered with AJAX communication

I've created the jQuery code below. The first AJAX call returns a list of states, however, the second AJAX call does not display any results for cities. <script> $(document).ready(function() { $("#cnt_id").change(function() { var id ...

How do I go about extracting and presenting the JSON data from the ESPN API?

In my current project, I am trying to utilize the jQuery library to work with API JSON data. Even though I am experienced in parsing JSON in PHP, I want to explore doing it with jQuery this time around. The goal is to extract information about each of the ...

Texture on plane is not displaying properly in Three.JS

Seeking assistance! I've been struggling all day to successfully load a texture onto my plane in Three.JS. Every time I attempt to add the desired link, it either fails or *poof* my plane disappears mysteriously. Please lend me your expertise with Thr ...

JavaScript Promise Synchronization

I have a JavaScript function that returns an object using promises. The first time the function is called, it fetches the object, but for subsequent calls, it returns a cached instance. To simulate the fetching process, I've added a delay. var Promis ...

Revamp your arrays with input fields in Vue3

When presented with two arrays of options, users must select an option from each array. ==> first array: [ orange, green, yellow ] ==> second array: [ orange, green, yellow ] The challenge is to update the second array based on the user's sele ...

Steps for deploying a monorepo using turborepo on Digital Ocean

I am working with a monorepo managed by turborepo. It consists of two packages - 'client' and 'api', located inside packages/* in the root folder. My current challenge is deploying the 'api' package to Digital Ocean, but I&apo ...

Adding externally hosted javascript files to Angular2

I'm attempting to integrate an external JavaScript file into my Angular2 project by modifying the angular-cli.json configuration file. The file has been added to the [scripts] array in the following manner: "scripts": ["https://as-identitydemo--c.na ...

Setting up Node.js with socket.io and nginx for optimal performance

I have a basic website running on node.js that sends messages to socket.io within the same node.js instance. Everything works smoothly on localhost, but I encounter issues when trying to set up nginx on my VPS as the client is unable to locate my socket.io ...

In Internet Explorer 8, the jQuery UI Tooltip is closing abruptly

Scenario We are encountering an issue with a jQuery UI tooltip that is triggered by a mouseenter event on the <div class="fieldset"> (.fieldset) element within a form. The problem arises in IE8, where the tooltip disappears immediately upon hovering ...

What is the best way to update the text of a Bootstrap-vue tooltip based on a condition?

Would appreciate some guidance on changing a Bootstrap-vue tooltip text conditionally with a checkbox. How can I access the tooltip text to make changes based on checkbox selection? Below is a Vue component where a checkbox attempts to modify a tooltip: ...

Is there a way to upload a file using express/multer without triggering a redirect?

Note: Despite coming across this post, I couldn't find it helpful. Other related posts were focused on angular/react, which are not relevant to my current project. I have implemented a file upload feature that should provide a response indicating whe ...

Updating a property within an object in Vue using Pinia

I am currently utilizing the pinia library and I am seeking guidance on how to update a property within an object. Within my state.cart, I have an array of objects representing various products, all of which contain a property named quantity. As this quant ...

Properly managing a laravel + vue.js (laravue) application: Best practices

Before diving in, I want to acknowledge that this question may be considered basic. I stumbled upon this Laravel and Vue.js dashboard fusion called laravue that caught my interest. I wanted to experiment with it before embarking on a real web application ...

Tips for creating a dynamic menu item that stands out with a highlighted style

I would like to add a colored square to highlight the active menu item. .main-menu ul { padding: 0; margin: 0; text-align: center; } .main-menu li { list-style-type: none; display: inline-block; padding: 40px 0; } .main-menu a { font-fam ...

Can Dropdown Items Be Generated Dynamically?

In the realm of React development, I find myself in need of a specific number of dropdown menus for a particular project. Each dropdown menu is expected to offer multiple options for selection. Typically, I would employ a straightforward map function to ha ...