#author("2022-05-14T13:28:10+08:00","default:Admin","Admin")
#author("2022-05-26T12:50:53+08:00","default:Admin","Admin")
[[Vue]]

&color(red){※前提条件:本文基于 Vue 2.0 创作};
#contents

* 概要 [#oce1d5c8]

methods:{ } 里是写各种不同的方法函数,这些方法可以理解为是一个属性,因为调用这个方法的时候,最终返回的是一个值

#codeprettify{{
methods: {
  greet(time) {
    return `Good ${time}`;
  }
}
}}

* 方法的调用 [#n76ae0bd]

可以在Mastache 表达式中使用

#codeprettify{{
<div id="app">
    {{ greet(time) }}
    \{\{ greet(time) \}\}
</div>
}}

* 注意 [#q815f9bd]

data 里面调用 methods 方法需要在方法前面加上 &color(red){this};

#codeprettify{{
data: {
  return {
     this.greet('11');
  }
}
}}


#hr();
コメント:
#comment_kcaptcha

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS