Which file should be referenced by the prototype prototype extension in vue

String.prototype.startsWith = function (str) {
  if (str == null || str == "" || this.length == 0 || str.length > this.length) {
    return false;
  }

  if (this.substring(0, s.length) == str) {
    return true;
  } else {
    return false;
  }
  return true;
}-sharp-sharp-sharp 

the environmental background of the problems and what methods you have tried

I can"t put it directly in the script tag

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Jan.08,2022

can be placed in main.js.
but look at your code, the ES6 string extends this function, and you don't have to write it yourself.
in addition, extending the existing JS type directly is not a recommended approach.


can be added to index.html, just as you introduce third-party scripts.

ES6 has related functions, why do you extend it? string extension includes (), startsWith (), endsWith ()-ECMAScript 6 getting started-Ruan Yifeng

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2c244-2bb03.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2c244-2bb03.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?