后端碼農(nóng),前端學(xué)習(xí)中,問題很簡(jiǎn)單,別噴我。
我的代碼:
export default {
name: 'hello',
data () {
return {
msg: 'welcome',
object:{
name: 'Runoob' ,
url: 'Google' ,
slogan: 'Taobao'
}
}
},
methods:{
doSomething: function(){
this.msg = 'welcome BeiJing'
}
},
computed:{
reversedMessage:function(){
return this.msg.split('').reverse().join('');
},
site: {
// getter
get: function () {
return this.name + ' ' + this.url
},
// setter
set: function (newValue) {
var names = newValue.split(' ')
this.name = names[0]
this.url = names[names.length - 1]
}
}
}
};
// 調(diào)用 setter, vm.name 和 vm.url 也會(huì)被對(duì)應(yīng)更新
vm.site = '菜鳥教程 https://www.runoob.com';
document.write('name: ' + vm.name);
document.write('<br>');
document.write('url: ' + vm.url);
我的報(bào)錯(cuò):
HelloWorld.vue?18db:72 Uncaught ReferenceError: vm is not defined
at eval (HelloWorld.vue?18db:72)
at Object../node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/HelloWorld.vue (app.js:758)
at __webpack_require__ (app.js:679)
at fn (app.js:89)
at eval (HelloWorld.vue?9042:1)
at Object../src/components/HelloWorld.vue (app.js:1039)
at __webpack_require__ (app.js:679)
at fn (app.js:89)
at eval (selector.js?type=script&index=0!./src/App.vue:1)
at Object../node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue (app.js:750)
(anonymous) @ HelloWorld.vue?18db:72
./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/HelloWorld.vue @ app.js:758
__webpack_require__ @ app.js:679
fn @ app.js:89
(anonymous) @ HelloWorld.vue?9042:1
./src/components/HelloWorld.vue @ app.js:1039
__webpack_require__ @ app.js:679
fn @ app.js:89
(anonymous) @ selector.js?type=script&index=0!./src/App.vue:1
./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue @ app.js:750
__webpack_require__ @ app.js:679
fn @ app.js:89
(anonymous) @ App.vue?a8e9:1
./src/App.vue @ app.js:1024
__webpack_require__ @ app.js:679
fn @ app.js:89
(anonymous) @ main.js?1c90:1
./src/main.js @ app.js:1047
__webpack_require__ @ app.js:679
fn @ app.js:89
0 @ app.js:1064
__webpack_require__ @ app.js:679
(anonymous) @ app.js:725
(anonymous) @ app.js:728
vue.esm.js?efeb:8566 You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html
sockjs.js?3600:1605 XHR finished loading: GET "http://localhost:8080/sockjs-node/info?t=1535449391140".
更新:我好像知道樓主的問題在哪了。
一方面樓主想手動(dòng)去vm.data
的方式體驗(yàn)vue
。 另一方面,卻又使用了webpack
工具。
1.你如果想去vm.data 觀察數(shù)據(jù)變化,
那你恐怕就得采用樓上的方法,不要用webpack
構(gòu)建工具
直接let vm = new Vue(...)
;
2.我就是想用webpack
,怎么解決?
那就不要用vm.data
這樣的方法了,
直接在mounted
方法里執(zhí)行this.data.name = "老王"
3.你仔細(xì)看菜鳥教程里的,他也是
let vm = new Vue(...);
4.總結(jié)
如果是剛開始接觸想體驗(yàn)vue, 那就直接html頁(yè)面上引入vue.js, 按照菜鳥教程/vue官網(wǎng)的教程
對(duì)照著敲(因?yàn)檫@些教程都是這種方式來的,比較容易上手)。覺得差不多再結(jié)合webpack腳手架,看一些實(shí)戰(zhàn)DEMO
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國(guó)家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問,美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。