Vue encountered an unexpected issue: fn.bind is not recognized as a function

My Vue application structure is as follows:

<template>
  <div id="app">
    <home-central></home-central>
  </div>

</template>

<script>
import HomeCentral from './components/HomeCentral';

export default {
  name: 'App',
  components: {
    HomeCentral,
  },
};
</script>
<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

The code in my HomeCentral component (src/components/HomeCentral.vue) looks like this:

<template>
    <div class="homecentral">
        <input type="text" v-model="title"><br/>
        <h1>{{title}}</h1>
        <p v-if="showName">{{user.first_name}}</p>
        <p v-else>Nobody</p>
        <ul>
            <li v-for="item in items" :key="item.id">{{item.title}}</li>it
        </ul>
        <button v-on:click="greet('Hello World')">Say Greeting</button>
        <br/>
        <input type="text" v-on:keyup="pressKey" v-on:keyup.enter="enterHit">
        <label>First Name: </label><input type="text" v-model="user.firstName">
        <br/>
        <label>Last Name: </label><input type="text" v-model="user.lastName">
        <h3></h3>
    </div>
</template>

<script>
export default {
  name: 'HomeCentral',
  data() {
    return {
      title: 'Welcome',
      user: {
        firstName: 'John',
        lastName: 'Doe',
      },
      showName: true,
      items: [
          { title: 'Item One' },
          { title: 'Item Two' },
          { title: 'Item Three' },
      ],
    };
  },
  methods: {
    greet: function (greeting) {
      alert(greeting);
    },
    pressKey: function (e){
      console.log('pressed' + e.target.value);
    },
    enterHit() {
      console.log('You hit enter');
    }
  },
};
</script>

<style scoped>

</style>

An error occurs when the computed property is included:

vue.runtime.esm.js?ff9b:205 Uncaught TypeError: fn.bind is not a function
    at nativeBind (vue.runtime.esm.js?ff9b:205)
    at initMethods (vue.runtime.esm.js?ff9b:3537)
    at initState (vue.runtime.esm.js?ff9b:3305)
    at VueComponent.Vue._init (vue.runtime.esm.js?ff9b:4624)
    at new VueComponent (vue.runtime.esm.js?ff9b:4794)
    at createComponentInstanceForVnode (vue.runtime.esm.js?ff9b:4306)
    at init (vue.runtime.esm.js?ff9b:4127)
    at createComponent (vue.runtime.esm.js?ff9b:5604)
    at createElm (vue.runtime.esm.js?ff9b:5551)
    at createChildren (vue.runtime.esm.js?ff9b:5678)

The issue disappears when the computed block is removed. Any ideas on what's causing this?

Answer №1

Ensure that the methods block only includes javascript functions. An error may occur if there is a nested object with methods inside the methods block.

For example:

methods: {
  namespace: {
    methodName () {
    }
  }
}

Should be changed to

methods: {
  namespace-methodName () {
  }
}

Answer №2

Kindly insert the code below and give it a try:

<template>
<div class="homecentral">
    <input type="text" v-model="title"><br/>
    <h1>{{title}}</h1>
    <p v-if="showName">{{user.first_name}}</p>
    <p v-else>Nobody</p>
    <ul>
        <li v-for="item in items" :key="item.id">{{item.title}}</li>it
    </ul>
    <button v-on:click="greet('Hello World')">Say Greeting</button>
    <br/>
    <input type="text" v-on:keyup="pressKey" v-on:keyup.enter="enterHit">
    <label>First Name: </label><input type="text" v-model="user.firstName">
    <br/>
    <label>Last Name: </label><input type="text" v-model="user.lastName">
    <h3></h3>

</div>
</template>

<script>
export default {
name: 'HomeCentral',
data() {
return {
  title: 'Welcome',
  user: {
    firstName: 'John',
    lastName: 'Doe',
  },
  showName: true,
  items: [
      { title: 'Item One' },
      { title: 'Item Two' },
      { title: 'Item Three' },
  ],
};
},
methods: {
greet: function (greeting) {
  alert(greeting);
},
pressKey: function (e){
  console.log('pressed' + e.target.value);
},
enterHit() {
  console.log('You hit enter');
}
},
computed: {
  fullName: function() {
    return this.user.firstName + ' ' + this.user.lastName;
  }    
},
};
</script>

<style scoped>

</style>

You mistakenly nested computed inside methods.

Answer №3

My initial code was

created: {

}

but it should have been

created() {

}

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

I possess a variety of poppers and desire for the opened one to close when another one is opened

Having built a component that generates 6 unique experiences, each with its own popper containing images, I am struggling to figure out how to modify my code so that one popper closes when another is clicked. Here is the current setup: This is the compone ...

The NodeJS module 'request' is producing symbols instead of expected HTML content

Currently, I am delving into the world of Nodejs and experimenting with web scraping using node.js. My tools of choice are the node modules request and cheerio. However, when I attempt to request a URL, instead of receiving the HTML body, I get strange s ...

A guide on accessing JavaScript files from the components directory in a React Native iOS application

I am encountering difficulty in accessing the components folder within my React Native Project on IOS. The error message I am receiving is: Unable to resolve module ./Login from ....../ReactNative/ReactNativeProject/components/App.js: Unable to find ...

Utilizing an Angular foreach loop for restructuring JSON data

I currently have an ng-repeat function that outputs arrays of objects in the following format: [ {"day":"10","title":"day","summary":"summary","description":"ok","_id":"53f25185bffedb83d8348b22"}, {"day":"3","title":"day","summary":"summary","description" ...

Dynamic routing with ngIf in Angular 2's router system

Is there a way to use *ngIf with dynamic router in Angular? Let's say I have a top navigation component with a back button, and I only want the back button to be visible on the route 'item/:id'. I tried using *ngIf="router.url == '/ite ...

Combining arrays into an Object with zipped keys and values

I have some data that I am working with var foo = ['US','MX','NZ']; var foo1 = [12',13',17]; var Object = {}; I attempted a solution by doing the following var Object = {foo:foo1} Unfortunately, this approa ...

Nodemailer is functioning properly in a local environment, however, it is encountering issues when

I am facing an issue with Nodemailer where it is sending emails successfully on my local machine but not on Lambda. I have tried various solutions from Stack Overflow, but none of them seem to be working for me. One suggestion was to make the sendEmail fun ...

Avoid VSCode from converting Vuejs code to vertical position upon saving

My Text Editor Formatting Issue ... is causing my code to be displayed vertically with too many lines. While it may make it easier to read, I find it tedious and unnecessary as it makes the file longer than needed. https://i.sstatic.net/FrGO2.png Could ...

Guide on executing dynamic queries with MySQL in Meteor

Attempting to execute dynamic queries against MySQL in Meteor using the numtel:mysql package has proven unsuccessful thus far. It seems that either I need guidance on passing dynamic arguments to the subscribe function, or I need to learn how to retrieve ...

Delete an item from an array when a dropdown selection is made

When dealing with Angular 8, I encountered a logic issue. There are two drop-down menus: First Drop-down The options in the first menu are populated from an array of objects Example Code, ts: {rs_id: "a5f100d5-bc88-4456-b507-1161575f8819", ...

Element not recognized: <my-company-form-extra> - have you properly registered this component?

I've been attempting to render a component using the is directive <template> <div> <v-tabs v-model="currentTab" fixed-tabs> <v-tab v-for="(item, i) in tabItems" :key="i">{{ item }} < ...

What is the process for uploading an image encoded in base64 through .ajax?

I am currently working with JavaScript code that successfully uploads an image to a server using an AJAX call. Here is the ajax call snippet that is functioning properly. $.ajax({ url: 'https://api.projectoxford.ai/vision/v1/analyses?', ...

Implementing an API call using Redux Saga within a React application

I have been diving into learning saga by following a tutorial on Medium and trying to implement it in StackBlitz. I encountered a path issue initially, managed to fix it after several attempts, but now a different problem has come up. Despite searching on ...

Link the getters to the data attribute -> the data attribute remains static

I have a question about assigning getters to my data "lang". Everything seems to be working fine, but I've noticed that when I change the language and the value of my getters changes accordingly, the actual value of my "lang" data does not update. da ...

Is it possible to adjust the width of the comment box on the Facebook "Like" button?

Is there a way to set the width of the comment box that appears after clicking the Facebook "Like" button? I know how to adjust the width of the button itself and related content, but can't find any options for the comment box: I've tried overri ...

What is the best way to create a sleek typewriter effect transition by hovering between tabs?

When hovering over a tab, the content in the main content area's child div should be displayed from a sibling div that holds the content. Initially, the details div style is set to hide the contents but upon hover, it is displayed. The described func ...

Flag form field as invalid in AngularJS

Struggling to implement server-side form validation in an AngularJS app? Finding it tricky to invalidate a form field and show an error message? Here's the setup of my app: I have a model 'client' with a controller Accounts.controller(&ap ...

What is the best way to load a targeted quantity of content on a social media platform's webpage?

Building a social media style platform, I attempted to simulate multiple users being active by opening several tabs. To my surprise, when checking the task manager, I found my Apache web server was consuming around 20% of CPU. After some debugging and scri ...

I am experiencing an issue where the images are not appearing properly within the <el-carousel></el-carousel> component of Element-ui

I'm having trouble displaying images in Element-ui using the Vue Framework. The images are not showing up on the page and I am fairly new to working with Vue. Can anyone offer assistance in resolving this issue? <template> <div> <el-c ...

Can Microsoft Edge Developer tool be used to incorporate external programs or code?

This image of msedge-devtools clearly demonstrates my point. I am interested in building a webpage parser using selenium and Microsoft Edge, beyond just JavaScript. I am seeking a way to utilize the Microsoft Edge developer tools (Inspect Element Mode) t ...