我对js和vue不太熟悉-一个初学者的问题。也许有人想帮助我解决问题。
如何将任何开关(toggle-btn)的更改转移到Django(-rest)-类似于“ this。$ http.post('/ api / tree / $ { tree-id }',...?)...?“。 tree-id(由Django确定)例如:/ tree / 805114 /
...
<head>
<link type="text/css" rel="stylesheet" href="vue/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="vue/css/bootstrap-vue.css" />
<script src=vue/js/vue.js ></script>
<script src=vue/js/polyfill.min.js ></script>
<script src=vue/js/bootstrap-vue.js ></script>
</head><body>
<div id="app">
<ul><li>
<a href="/tree/805114/"><b>805114</b> <48.11478.0></a>
<toggle-btn initial='0'> </toggle-btn>
<ul><li>
<a href="/tree/825386/"><b>825386</b> <44.33508.0></a>
<toggle-btn initial='0'> </toggle-btn>
</li>
<li>
<a href="/tree/814216/"><b>814216</b> <8.1181615.0></a>
<toggle-btn initial='0'> </toggle-btn>
<ul><li>
<a href="/tree/814215/"><b>814215</b> <32.1181615.0></a>
<toggle-btn initial='0'> </toggle-btn>
</li></ul>
</li></ul>
</li></ul>
</div>
<script src=js/simplebutton.vue ></script>
</body>
...
const ToggleStatus = ('toggle-btn', {
data: function() {
return {
currenValue: this.initial
}
},
props: {
initial: {
type: String,
required: false,
default: '0'
}
},
methods: {
set_value: function () {
if (this.currenValue !=1) {
this.currenValue = 1;
} else {
this.currenValue = 0;
}
}
},
template: '<button v-on:click="set_value">{{ currenValue }}</button>'
});
const my = new Vue ({
el: "#app",
components: { 'toggle-btn': ToggleStatus },
});